JSON: Kinda fixed comment issue (#1853) 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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
diff --git a/components/prism-json.js b/components/prism-json.js
index 5f40179..2352c38 100644
--- a/components/prism-json.js
+++ b/components/prism-json.js
@@ -1,5 +1,4 @@
Prism.languages.json = {
- 'comment': /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,
'property': {
pattern: /"(?:\\.|[^\\"\r\n])*"(?=\s*:)/,
greedy: true
@@ -8,6 +7,7 @@ Prism.languages.json = {
pattern: /"(?:\\.|[^\\"\r\n])*"(?!\s*:)/,
greedy: true
},
+ 'comment': /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,
'number': /-?\d+\.?\d*(e[+-]?\d+)?/i,
'punctuation': /[{}[\],]/,
'operator': /:/,
diff --git a/components/prism-json.min.js b/components/prism-json.min.js
index 6ea539d..b67c29f 100644
--- a/components/prism-json.min.js
+++ b/components/prism-json.min.js
@@ -1 +1 @@
-Prism.languages.json={comment:/\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,property:{pattern:/"(?:\\.|[^\\"\r\n])*"(?=\s*:)/,greedy:!0},string:{pattern:/"(?:\\.|[^\\"\r\n])*"(?!\s*:)/,greedy:!0},number:/-?\d+\.?\d*(e[+-]?\d+)?/i,punctuation:/[{}[\],]/,operator:/:/,boolean:/\b(?:true|false)\b/,null:{pattern:/\bnull\b/,alias:"keyword"}};
\ No newline at end of file
+Prism.languages.json={property:{pattern:/"(?:\\.|[^\\"\r\n])*"(?=\s*:)/,greedy:!0},string:{pattern:/"(?:\\.|[^\\"\r\n])*"(?!\s*:)/,greedy:!0},comment:/\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,number:/-?\d+\.?\d*(e[+-]?\d+)?/i,punctuation:/[{}[\],]/,operator:/:/,boolean:/\b(?:true|false)\b/,null:{pattern:/\bnull\b/,alias:"keyword"}};
\ No newline at end of file
diff --git a/tests/languages/json/issue1852.test b/tests/languages/json/issue1852.test
new file mode 100644
index 0000000..5ed99c0
--- /dev/null
+++ b/tests/languages/json/issue1852.test
@@ -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.