Skip to content

Commit

Permalink
JSON: Kinda fixed comment issue (#1853)
Browse files Browse the repository at this point in the history
This is a partial workaround for the greedy matching bug so that pure JSON will always be matched correctly while JSON + comments might suffer from some issues.
  • Loading branch information
RunDevelopment committed Apr 23, 2019
1 parent 77e403c commit cbe05ec
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components/prism-json.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Prism.languages.json = {
'comment': /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,
'property': {
pattern: /"(?:\\.|[^\\"\r\n])*"(?=\s*:)/,
greedy: true
Expand All @@ -8,6 +7,7 @@ Prism.languages.json = {
pattern: /"(?:\\.|[^\\"\r\n])*"(?!\s*:)/,
greedy: true
},
'comment': /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,
'number': /-?\d+\.?\d*(e[+-]?\d+)?/i,
'punctuation': /[{}[\],]/,
'operator': /:/,
Expand Down
2 changes: 1 addition & 1 deletion components/prism-json.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions tests/languages/json/issue1852.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"A": "/*",
"B": "B",
"C": "C"
}

----------------------------------------------------

[
["punctuation", "{"],
["property", "\"A\""],
["operator", ":"],
["string", "\"/*\""],
["punctuation", ","],
["property", "\"B\""],
["operator", ":"],
["string", "\"B\""],
["punctuation", ","],
["property", "\"C\""],
["operator", ":"],
["string", "\"C\""],
["punctuation", "}"]
]

----------------------------------------------------

Checks for issue #1852.

0 comments on commit cbe05ec

Please sign in to comment.