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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyhocon/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

}

period_type_map = {
Expand Down