-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Skip to load commented out words #7413
Conversation
37533bd
to
edefc95
Compare
edefc95
to
54b67fb
Compare
@hsbt sorry If I'm getting on your way... I'm just trying to contribute with something.. does it make sense to use a regex for this? or update the current ones? I think I manage to pass some specs with something: REMOVE_COMMENT_REGEX = /
^
(["']?) # optional opening quote
(.*?) # match for characters between quotes
\1 # matching closing quote
\s* # Optional whitespace characters after the closing quote
(?:\#(.*))? # optional comment starting with '#'
$
/xo
...
# and then call it when needed:
if val == "[]" # empty array
val = []
else
val = val.match(REMOVE_COMMENT_REGEX)[2]
end would pass this: it "ignore comments" do
yaml = <<~YAML
---
Foo: "Lobster shouldn't go # should stay!" # test
Bar: Something without quote! # another comment
Mick: "Not... but crambs yes!"#test
empty:
YAML
hash = {
"Foo" => "Lobster shouldn't go # should stay!",
"Bar" => "Something without quote!",
"Mick" => "Not... but crambs yes!",
"empty" => {},
}
expect(serializer.load(yaml)).to eq(hash)
end this would support I can try a PR as well, if you don't mind.. |
@williantenfen Thanks for your support! I only focused configuration file for rubygems. If you interest to improve this PR, feel free to submit your idea and changes 👍 |
@@ -80,6 +84,14 @@ def load(str) | |||
res | |||
end | |||
|
|||
def strip_comment(val) | |||
if val.include?("#") && !val.start_with?("#") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given this is operating on a new string, we can avoid the array & string allocations by using val.sub!(/#.*/, "")
Skip to load commented out words (cherry picked from commit 53604cb)
What was the end-user or developer problem that led to this PR?
Fixes #7393
The current YAML serializer couldn't handle commented out words.
What is your fix for the problem, implemented in this PR?
Skip to load after
#
symbol.Make sure the following tasks are checked