Skip to content

Commit

Permalink
JSON: Fixed issues with properties and strings + added tests. Fix #1025
Browse files Browse the repository at this point in the history
  • Loading branch information
Golmote committed Sep 28, 2016
1 parent 5916430 commit 25a541d
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 5 deletions.
8 changes: 4 additions & 4 deletions components/prism-json.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Prism.languages.json = {
'property': /".*?"(?=\s*:)/ig,
'string': /"(?!:)(\\?[^"])*?"(?!:)/g,
'number': /\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee]-?\d+)?)\b/g,
'property': /"(?:\\.|[^|"])*"(?=\s*:)/ig,
'string': /"(?!:)(?:\\.|[^|"])*"(?!:)/g,
'number': /\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee][+-]?\d+)?)\b/g,
'punctuation': /[{}[\]);,]/g,
'operator': /:/g,
'boolean': /\b(true|false)\b/gi,
'null': /\bnull\b/gi,
'null': /\bnull\b/gi
};

Prism.languages.jsonp = Prism.languages.json;
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.

13 changes: 13 additions & 0 deletions tests/languages/json/boolean_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
true
false

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

[
["boolean", "true"],
["boolean", "false"]
]

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

Checks for booleans.
11 changes: 11 additions & 0 deletions tests/languages/json/null_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
null

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

[
["null", "null"]
]

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

Checks for null.
21 changes: 21 additions & 0 deletions tests/languages/json/number_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
0
123
3.14159
5.0e8
0.2E+2
47e-5

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

[
["number", "0"],
["number", "123"],
["number", "3.14159"],
["number", "5.0e8"],
["number", "0.2E+2"],
["number", "47e-5"]
]

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

Checks for numbers.
33 changes: 33 additions & 0 deletions tests/languages/json/property_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{"foo\"bar\"baz":1,"foo":2}
{
"foo": 1,
"b\"ar": 2
}

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

[
["punctuation", "{"],
["property", "\"foo\\\"bar\\\"baz\""],
["operator", ":"],
["number", "1"],
["punctuation", ","],
["property", "\"foo\""],
["operator", ":"],
["number", "2"],
["punctuation", "}"],

["punctuation", "{"],
["property", "\"foo\""],
["operator", ":"],
["number", "1"],
["punctuation", ","],
["property", "\"b\\\"ar\""],
["operator", ":"],
["number", "2"],
["punctuation", "}"]
]

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

Checks for features.
27 changes: 27 additions & 0 deletions tests/languages/json/string_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
""
"foo"
"foo\"bar\"baz"
"\u2642\\ "
{"foo":"bar","baz":"\""}

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

[
["string", "\"\""],
["string", "\"foo\""],
["string", "\"foo\\\"bar\\\"baz\""],
["string", "\"\\u2642\\\\ \""],
["punctuation", "{"],
["property", "\"foo\""],
["operator", ":"],
["string", "\"bar\""],
["punctuation", ","],
["property", "\"baz\""],
["operator", ":"],
["string", "\"\\\"\""],
["punctuation", "}"]
]

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

Checks for strings.

0 comments on commit 25a541d

Please sign in to comment.