Skip to content

Commit bda9879

Browse files
pe4ceymarijnh
authored andcommitted
[cypher mode] Handle unbalanced strings
1 parent aada390 commit bda9879

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

mode/cypher/cypher.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@
2020
CodeMirror.defineMode("cypher", function(config) {
2121
var tokenBase = function(stream/*, state*/) {
2222
var ch = stream.next();
23-
if (ch === "\"" || ch === "'") {
24-
stream.match(/.+?["']/);
23+
if (ch === "\"") {
24+
stream.match(/.+?["]/);
25+
return "string";
26+
}
27+
if (ch === "'") {
28+
stream.match(/.+?[']/);
2529
return "string";
2630
}
2731
if (/[{}\(\),\.;\[\]]/.test(ch)) {

mode/cypher/test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
2+
// Distributed under an MIT license: http://codemirror.net/LICENSE
3+
4+
(function() {
5+
var mode = CodeMirror.getMode({tabSize: 4, indentUnit: 2}, "cypher");
6+
function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); }
7+
8+
MT("unbalancedDoubledQuotedString",
9+
"[string \"a'b\"][variable c]");
10+
11+
MT("unbalancedSingleQuotedString",
12+
"[string 'a\"b'][variable c]");
13+
14+
MT("doubleQuotedString",
15+
"[string \"a\"][variable b]");
16+
17+
MT("singleQuotedString",
18+
"[string 'a'][variable b]");
19+
})();

test/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<script src="../mode/css/css.js"></script>
2121
<script src="../mode/clike/clike.js"></script>
2222
<!-- clike must be after css or vim and sublime tests will fail -->
23+
<script src="../mode/cypher/cypher.js"></script>
2324
<script src="../mode/gfm/gfm.js"></script>
2425
<script src="../mode/haml/haml.js"></script>
2526
<script src="../mode/htmlmixed/htmlmixed.js"></script>
@@ -109,6 +110,7 @@ <h2>Test Suite</h2>
109110
<script src="../mode/css/gss_test.js"></script>
110111
<script src="../mode/css/scss_test.js"></script>
111112
<script src="../mode/css/less_test.js"></script>
113+
<script src="../mode/cypher/test.js"></script>
112114
<script src="../mode/gfm/test.js"></script>
113115
<script src="../mode/haml/test.js"></script>
114116
<script src="../mode/javascript/test.js"></script>

0 commit comments

Comments
 (0)