Skip to content
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

Fail on escape sequences in metadata.json #152

Merged
merged 2 commits into from
Jan 24, 2025

Conversation

bastelfreak
Copy link
Member

@bastelfreak bastelfreak commented Jan 24, 2025

This is an enhancement of #120

We now use a regex to identify invalid escape sequences. JSON.parse()
has no built-in way to detect this. Even in strict mode it ignores it:

irb(main):002> require 'json'
=> true
irb(main):003> JSON.parser = JSON::Ext::Parser
=> JSON::Ext::Parser
irb(main):004> JSON.parse('{"summary": "A description with an invalid \( escape sequence"}')
=> {"summary"=>"A description with an invalid ( escape sequence"}
irb(main):005> JSON.parse("{\"summary\": \"A description with an invalid \( escape sequence\"}")
=> {"summary"=>"A description with an invalid ( escape sequence"}
irb(main):006>

@bastelfreak bastelfreak self-assigned this Jan 24, 2025
Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wondered if this really was invalid, but it looks like Ruby's JSON parser just silently ignores it while Python raises a hard JSONDecodeError so 👍 for enforcing it as an error. https://jsonlint.com/ also loudly complains about "\(".

lib/metadata_json_lint.rb Outdated Show resolved Hide resolved
tests/invalid_escape_char/metadata.json Outdated Show resolved Hide resolved
@bastelfreak
Copy link
Member Author

I wondered if this really was invalid
me too, but jq also complains:

bastelfreak@bastelfreak-nb ~/code/metadata-json-lint $ jq . tests/invalid_escape_char/metadata.json
jq: parse error: Invalid escape at line 5, column 63
bastelfreak@bastelfreak-nb ~/code/metadata-json-lint $

@bastelfreak bastelfreak force-pushed the test_for_invalid_escape branch 3 times, most recently from b0eb7bf to 2c7837c Compare January 24, 2025 13:02
timidri and others added 2 commits January 24, 2025 18:19
This is an enhancement of voxpupuli#120

We now use a regex to identify invalid escape sequences. `JSON.parse()`
has no built-in way to detect this. Even in strict mode it ignores it:

```
irb(main):002> require 'json'
=> true
irb(main):003> JSON.parser = JSON::Ext::Parser
=> JSON::Ext::Parser
irb(main):004> JSON.parse('{"summary": "A description with an invalid \( escape sequence"}')
=> {"summary"=>"A description with an invalid ( escape sequence"}
irb(main):005> JSON.parse("{\"summary\": \"A description with an invalid \( escape sequence\"}")
=> {"summary"=>"A description with an invalid ( escape sequence"}
irb(main):006>
```
@bastelfreak bastelfreak force-pushed the test_for_invalid_escape branch from 2c7837c to f0b04de Compare January 24, 2025 17:19
@bastelfreak bastelfreak merged commit d0c1cd5 into voxpupuli:master Jan 24, 2025
8 checks passed
@bastelfreak bastelfreak deleted the test_for_invalid_escape branch January 24, 2025 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants