Skip to content

Commit

Permalink
Batch: Fix escaped double quote (#2485)
Browse files Browse the repository at this point in the history
  • Loading branch information
proudust authored Jul 27, 2020
1 parent 649e51e commit f0f8210
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
6 changes: 3 additions & 3 deletions components/prism-batch.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
'punctuation': /:/
}
};
var string = /"[^"]*"/;
var string = /"(?:[\\"]"|[^"])*"(?!")/;
var number = /(?:\b|-)\d+\b/;

Prism.languages.batch = {
Expand Down Expand Up @@ -76,7 +76,7 @@
},
{
// Other commands
pattern: /((?:^|[&(])[ \t]*@?)\w+\b(?:[^^&)\r\n]|\^(?:\r\n|[\s\S]))*/im,
pattern: /((?:^|[&(])[ \t]*@?)\w+\b(?:"(?:[\\"]"|[^"])*"(?!")|[^"^&)\r\n]|\^(?:\r\n|[\s\S]))*/im,
lookbehind: true,
inside: {
'keyword': /^\w+\b/i,
Expand All @@ -96,4 +96,4 @@
'operator': /[&@]/,
'punctuation': /[()']/
};
}(Prism));
}(Prism));
2 changes: 1 addition & 1 deletion components/prism-batch.min.js

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

29 changes: 29 additions & 0 deletions tests/languages/batch/string_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
cmd ""
cmd "f\"oo"
cmd "f\\"oo"
cmd "print(""hello"")"

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

[
["command", [
["keyword", "cmd"],
["string", "\"\""]
]],
["command", [
["keyword", "cmd"],
["string", "\"f\\\"oo\""]
]],
["command", [
["keyword", "cmd"],
["string", "\"f\\\\\"oo\""]
]],
["command", [
["keyword", "cmd"],
["string", "\"print(\"\"hello\"\")\""]
]]
]

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

Checks for strings.

0 comments on commit f0f8210

Please sign in to comment.