Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
fc58a735
Commit
fc58a735
authored
Apr 24, 2015
by
Niels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix #60 (double escaping)
parent
28f21c43
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
19 deletions
+30
-19
.gitignore
.gitignore
+2
-0
src/json.hpp
src/json.hpp
+5
-7
src/json.hpp.re2c
src/json.hpp.re2c
+5
-7
test/unit.cpp
test/unit.cpp
+18
-5
No files found.
.gitignore
View file @
fc58a735
json_unit
html
benchmark
src/json.hpp
View file @
fc58a735
...
...
@@ -2251,7 +2251,7 @@ class basic_json
{
// control characters (everything between 0x00 and 0x1f)
// -> create four-digit hex representation
std
::
stringstream
ss
;
std
::
basic_stringstream
<
typename
string_t
::
value_type
>
ss
;
ss
<<
"
\\
u"
<<
std
::
hex
<<
std
::
setw
(
4
)
<<
std
::
setfill
(
'0'
)
<<
int
(
c
);
result
+=
ss
.
str
();
}
...
...
@@ -2391,7 +2391,7 @@ class basic_json
// 15 digits of precision allows round-trip IEEE 754
// string->double->string
const
auto
sz
=
static_cast
<
unsigned
int
>
(
std
::
snprintf
(
nullptr
,
0
,
"%.15g"
,
m_value
.
number_float
));
std
::
vector
<
char
>
buf
(
sz
+
1
);
std
::
vector
<
typename
string_t
::
value_type
>
buf
(
sz
+
1
);
std
::
snprintf
(
&
buf
[
0
],
buf
.
size
(),
"%.15g"
,
m_value
.
number_float
);
return
string_t
(
buf
.
data
());
}
...
...
@@ -4577,21 +4577,19 @@ basic_json_parser_59:
result
+=
"
\r
"
;
break
;
}
// characters that are not "un"escsaped
case
'\\'
:
{
result
+=
"
\\
\\
"
;
result
+=
"
\\
"
;
break
;
}
case
'/'
:
{
result
+=
"
\\
/"
;
result
+=
"/"
;
break
;
}
case
'"'
:
{
result
+=
"
\
\\
"
"
;
result
+=
"
\"
"
;
break
;
}
...
...
src/json.hpp.re2c
View file @
fc58a735
...
...
@@ -2251,7 +2251,7 @@ class basic_json
{
// control characters (everything between 0x00 and 0x1f)
// -> create four-digit hex representation
std::
stringstream
ss;
std::
basic_stringstream<typename string_t::value_type>
ss;
ss << "\\u" << std::hex << std::setw(4) << std::setfill('0') << int(c);
result += ss.str();
}
...
...
@@ -2391,7 +2391,7 @@ class basic_json
// 15 digits of precision allows round-trip IEEE 754
// string->double->string
const auto sz = static_cast<unsigned int>(std::snprintf(nullptr, 0, "%.15g", m_value.number_float));
std::vector<
char
> buf(sz + 1);
std::vector<
typename string_t::value_type
> buf(sz + 1);
std::snprintf(&buf[0], buf.size(), "%.15g", m_value.number_float);
return string_t(buf.data());
}
...
...
@@ -3883,21 +3883,19 @@ class basic_json
result += "\r";
break;
}
// characters that are not "un"escsaped
case '\\':
{
result += "\\
\\
";
result += "\\";
break;
}
case '/':
{
result += "
\\
/";
result += "/";
break;
}
case '"':
{
result += "\
\\
"";
result += "\"";
break;
}
...
...
test/unit.cpp
View file @
fc58a735
...
...
@@ -7328,12 +7328,12 @@ TEST_CASE("parser class")
SECTION
(
"escaped"
)
{
// quotation mark
CHECK
(
json
::
parser
(
"
\"\\\"\"
"
).
parse
()
==
json
(
"
\\\"
"
)
);
// reverse solidus
CHECK
(
json
::
parser
(
"
\"\\\\\"
"
).
parse
()
==
json
(
"
\\\\
"
)
);
// quotation mark
"\""
CHECK
(
json
::
parser
(
"
\"\\\"\"
"
).
parse
()
==
R"("\"")"
_json
);
// reverse solidus
"\\"
CHECK
(
json
::
parser
(
"
\"\\\\\"
"
).
parse
()
==
R"("\\")"
_json
);
// solidus
CHECK
(
json
::
parser
(
"
\"\\
/
\"
"
).
parse
()
==
json
(
"
\\
/"
)
);
CHECK
(
json
::
parser
(
"
\"\\
/
\"
"
).
parse
()
==
R"("/")"
_json
);
// backspace
CHECK
(
json
::
parser
(
"
\"\\
b
\"
"
).
parse
()
==
json
(
"
\b
"
));
// formfeed
...
...
@@ -8267,3 +8267,16 @@ TEST_CASE("concepts")
}
}
}
TEST_CASE
(
"regression tests"
)
{
SECTION
(
"issue #60 - Double quotation mark is not parsed correctly"
)
{
SECTION
(
"escape_dobulequote"
)
{
auto
s
=
"[
\"\\\"
foo
\\\"\"
]"
;
json
j
=
json
::
parse
(
s
);
CHECK
(
j
==
R"(["\"foo\""])"
_json
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment