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

Parse \/ correctly when input json #294

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

YK-Samgo
Copy link

#293

It seems not difficult to fix. But don' know side effect.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.8%) to 94.371% when pulling 628f923 on YK-Samgo:master into be660de on chimpler:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-1.8%) to 94.371% when pulling 628f923 on YK-Samgo:master into be660de on chimpler:master.

@@ -239,6 +239,7 @@ class ConfigParser(object):
'\\#': '#',
'\\!': '!',
'\\"': '"',
'\/': '/',
Copy link
Member

Choose a reason for hiding this comment

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

Should it be \\/ instead? Do you have an example where you use it?

Copy link
Author

@YK-Samgo YK-Samgo May 18, 2023

Choose a reason for hiding this comment

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

As shown in #293 , json use \/ in unix path string like {"path":"\/var"}.

pyhocon does not parse it correctly as jq does.

# echo '{"path":"\/var"}' | jq .
{
  "path": "/var"
}
# echo '{"path":"\/var"}' | pyhocon
{
  "path": "\\/var"
}

Copy link
Author

Choose a reason for hiding this comment

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

Python handles \ in a strange way. '\/', '\\/', "\/" and "\\/" all work.

Python 3.9.2 (default, Feb 28 2021, 17:03:44)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print('\/')
\/
>>> print("\/")
\/
>>> print("\\/")
\/
>>> print('\\/')
\/
>>> '\/var'.replace('\/','/')
'/var'
>>> '\/var'.replace('\\/','/')
'/var'
>>> '\/var'.replace("\/",'/')
'/var'
>>> '\/var'.replace("\\/",'/')
'/var'

Copy link
Author

Choose a reason for hiding this comment

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

This syntax is described in RFC 8259 Section 7 Strings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants