Skip to content

Commit

Permalink
[ruby mode] Only allow indented heredoc end markers when a - was present
Browse files Browse the repository at this point in the history
Issue #5728
  • Loading branch information
marijnh committed Jan 2, 2019
1 parent be9d254 commit 64f7d4c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 5 additions & 5 deletions mode/ruby/ruby.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ CodeMirror.defineMode("ruby", function(config) {
} else if (ch == "#") {
stream.skipToEnd();
return "comment";
} else if (ch == "<" && (m = stream.match(/^<-?[\`\"\']?([a-zA-Z_?]\w*)[\`\"\']?(?:;|$)/))) {
return chain(readHereDoc(m[1]), stream, state);
} else if (ch == "<" && (m = stream.match(/^<(-)?[\`\"\']?([a-zA-Z_?]\w*)[\`\"\']?(?:;|$)/))) {
return chain(readHereDoc(m[2], m[1]), stream, state);
} else if (ch == "0") {
if (stream.eat("x")) stream.eatWhile(/[\da-fA-F]/);
else if (stream.eat("b")) stream.eatWhile(/[01]/);
Expand Down Expand Up @@ -216,9 +216,9 @@ CodeMirror.defineMode("ruby", function(config) {
return style;
};
}
function readHereDoc(phrase) {
function readHereDoc(phrase, mayIndent) {
return function(stream, state) {
stream.eatSpace()
if (mayIndent) stream.eatSpace()
if (stream.match(phrase)) state.tokenize.pop();
else stream.skipToEnd();
return "string";
Expand Down Expand Up @@ -277,7 +277,7 @@ CodeMirror.defineMode("ruby", function(config) {
},

indent: function(state, textAfter) {
if (state.tokenize[state.tokenize.length-1] != tokenBase) return 0;
if (state.tokenize[state.tokenize.length-1] != tokenBase) return CodeMirror.Pass;
var firstChar = textAfter && textAfter.charAt(0);
var ct = state.context;
var closing = ct.type == matching[firstChar] ||
Expand Down
7 changes: 7 additions & 0 deletions mode/ruby/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,11 @@

MT("complex_regexp",
"[keyword if] [variable cr] [operator =~] [string-2 /(?: \\( #{][tag RE_NOT][string-2 }\\( | #{][tag RE_NOT_PAR_OR][string-2 }* #{][tag RE_OPA_OR][string-2 } )/][variable x]")

MT("indented_heredoc",
"[keyword def] [def x]",
" [variable y] [operator =] [string <<-FOO]",
"[string bar]",
"[string FOO]",
"[keyword end]")
})();

0 comments on commit 64f7d4c

Please sign in to comment.