-
Notifications
You must be signed in to change notification settings - Fork 6
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
fix(parser): Unable to parse json in one line #43
fix(parser): Unable to parse json in one line #43
Conversation
lua/curl/parser.lua
Outdated
cleaned_line = "'" .. cleaned_line | ||
|
||
is_line_json_close(json_nesting_stack, opening_json_char, closing_json_char, cleaned_line) |
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.
This function returns a boolean whether the line contains a json closer, however the result is never used.
Is the case fixed if you do the same as in the else branch instead?
local found_json_end =
is_line_json_close(json_nesting_stack, opening_json_char, closing_json_char, cleaned_line)
if found_json_end then
cleaned_line = cleaned_line .. "'"
end
If so, I think this method would be cleaner if the for loop looked like this:
for _, line in ipairs(lines) do
local cleaned_line = remove_trailing_forwardslash(line)
if found_first_json_char(json_nesting_stack, cleaned_line) then
opening_json_char = cleaned_line:sub(1, 1)
closing_json_char = opening_json_char == "[" and "]" or "}"
end
local found_json_end =
is_line_json_close(json_nesting_stack, opening_json_char, closing_json_char, cleaned_line)
if found_json_end then
cleaned_line = cleaned_line .. "'"
end
table.insert(cleaned_lines, cleaned_line)
end
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.
See the comment.
Also, I think we should have a test for the case that fails.
It can be added to "parser_spec.lua", there are other examples in that file.
After reading the code, I found that although this method did not use its return value, it operated on json_nesting_stack, which was critical. |
OK, I'll add the test case later. |
That's right, might not be the best design from my part hehe. But this check: |
lua/curl/parser.lua
Outdated
cleaned_line = "'" .. cleaned_line | ||
|
||
-- if the all json content is in one line |
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.
Dont need this comment, this if check will work for all cases
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.
That makes sense. It's been taken care of.
Looks very good! I just had a little nitpick |
Thank you so much for your contribution 😸 |
Look forward to your refactoring. 😀 |
about this #41