Skip to content

Commit

Permalink
fix: quote bugs
Browse files Browse the repository at this point in the history
 should replace " with \&quote;

[issue10](#10)
  • Loading branch information
colin.ck committed Jul 9, 2018
1 parent 7ddded2 commit 19de3e7
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion JSONPretty.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = createReactClass({
return text;
}

return text.replace(/&/g, '&').replace(/\\"([^,])/g, '"$1')
return text.replace(/&/g, '&').replace(/\\"([^,])/g, '\\"$1')
.replace(/</g, '&lt;').replace(/>/g, '&gt;')
.replace(regLine, this._replace);
},
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"eslint": "eslint JSONPretty.jsx",
"precommit": "npm run build && npm run eslint",
"prepush": "npm test",
"release": "standard-version",
"patch": "npm run release -- --release-as patch",
"build-styl-monikai": "stylus --compress < JSONPretty.monikai.styl > src/JSONPretty.monikai.css",
"build-styl-1337": "stylus --compress < JSONPretty.1337.styl > src/JSONPretty.1337.css",
"build-styl-acai": "stylus --compress < JSONPretty.acai.styl > src/JSONPretty.acai.css",
Expand Down Expand Up @@ -44,6 +46,7 @@
"react": "^15.5.4",
"react-dom": "^15.5.4",
"react-test-renderer": "^15.5.4",
"standard-version": "^4.4.0",
"stylus": "^0.54.5",
"webpack": "^2.4.1"
},
Expand Down
2 changes: 1 addition & 1 deletion src/JSONPretty.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = createReactClass({
return text;
}

return text.replace(/&/g, '&amp;').replace(/\\"([^,])/g, '&quot;$1').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(regLine, this._replace);
return text.replace(/&/g, '&amp;').replace(/\\"([^,])/g, '\\&quot;$1').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(regLine, this._replace);
},
render: function render() {

Expand Down
4 changes: 2 additions & 2 deletions tests/__snapshots__/pretty_js_snapshot.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ exports[`src/JSONPretty.js -- string 1`] = `
"__html": "{
\\"<span class=json-key>aaaa</span>\\": <span class=json-value>1</span>,
\\"<span class=json-key>bbbb</span>\\": <span class=json-boolean>true</span>,
\\"<span class=json-key>cccc</span>\\": <span class=json-string>\\"ab&quot;cd\\\\\\\\\\"</span>,
\\"<span class=json-key>cccc</span>\\": <span class=json-string>\\"ab\\\\&quot;cd\\\\\\\\\\"</span>,
\\"<span class=json-key>dddd</span>\\": {
\\"<span class=json-key>eeee</span>\\": <span class=json-value>1</span>,
\\"<span class=json-key>ffff</span>\\": [
Expand All @@ -44,7 +44,7 @@ exports[`src/JSONPretty.js 1`] = `
"__html": "{
\\"<span class=json-key>aaaa</span>\\": <span class=json-value>1</span>,
\\"<span class=json-key>bbbb</span>\\": <span class=json-boolean>true</span>,
\\"<span class=json-key>cccc</span>\\": <span class=json-string>\\"ab&quot;cd\\\\\\\\\\"</span>,
\\"<span class=json-key>cccc</span>\\": <span class=json-string>\\"ab\\\\&quot;cd\\\\\\\\\\"</span>,
\\"<span class=json-key>dddd</span>\\": {
\\"<span class=json-key>eeee</span>\\": <span class=json-value>1</span>,
\\"<span class=json-key>ffff</span>\\": [
Expand Down
4 changes: 2 additions & 2 deletions tests/__snapshots__/pretty_jsx_snapshot.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ exports[`JSONPretty.jsx -- String 1`] = `
\\"<span class=json-key>efef</span>\\": <span class=json-string>\\"true\\"</span>,
\\"<span class=json-key>efed</span>\\": <span class=json-string>\\"false\\"</span>,
\\"<span class=json-key>efee</span>\\": <span class=json-boolean>false</span>,
\\"<span class=json-key>cccc</span>\\": <span class=json-string>\\"ab&quot;cd\\\\\\\\\\"</span>,
\\"<span class=json-key>cccc</span>\\": <span class=json-string>\\"ab\\\\&quot;cd\\\\\\\\\\"</span>,
\\"<span class=json-key>dddd</span>\\": {
\\"<span class=json-key>eeee</span>\\": <span class=json-value>1</span>,
\\"<span class=json-key>ffff</span>\\": [
Expand Down Expand Up @@ -50,7 +50,7 @@ exports[`JSONPretty.jsx 1`] = `
\\"<span class=json-key>efef</span>\\": <span class=json-string>\\"true\\"</span>,
\\"<span class=json-key>efed</span>\\": <span class=json-string>\\"false\\"</span>,
\\"<span class=json-key>efee</span>\\": <span class=json-boolean>false</span>,
\\"<span class=json-key>cccc</span>\\": <span class=json-string>\\"ab&quot;cd\\\\\\\\\\"</span>,
\\"<span class=json-key>cccc</span>\\": <span class=json-string>\\"ab\\\\&quot;cd\\\\\\\\\\"</span>,
\\"<span class=json-key>dddd</span>\\": {
\\"<span class=json-key>eeee</span>\\": <span class=json-value>1</span>,
\\"<span class=json-key>ffff</span>\\": [
Expand Down

0 comments on commit 19de3e7

Please sign in to comment.