Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
Sense: trailing space after URL shouldn't break request parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
bleskes committed Feb 24, 2015
1 parent 9acf9b4 commit 0304b31
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
6 changes: 5 additions & 1 deletion sense/app/sense_editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ define([
request.url += t.value;
t = tokenIter.stepForward();
}
if (editor.parser.isEmptyToken(t)) {
// if the url row ends with some spaces, skip them.
t = editor.parser.nextNonEmptyToken(tokenIter);
}

var bodyStartRow = (t ? 0 : 1) + tokenIter.getCurrentTokenRow(); // artificially increase end of docs.
var bodyStartColumn = 0;
Expand Down Expand Up @@ -297,7 +301,7 @@ define([
}
}

var column = (session.getLine(curRow) || "").length;
var column = (session.getLine(curRow) || "").replace(/\s+$/, "").length;

return { row: curRow, column: column};
};
Expand Down
24 changes: 24 additions & 0 deletions sense/tests/src/editor_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,30 @@ define([
});
});

utils_test("simple request range, suffixed with spaces", simple_request.prefix + " ", simple_request.data + " ", function () {
input.getCurrentRequestRange(function (range) {
var expected = new aceRange.Range(
0, 0,
3, 1
);
deepEqual(range, expected);
start();
});
});

utils_test("simple request data, suffixed with spaces", simple_request.prefix + " " , simple_request.data + " ", function () {
input.getCurrentRequest(function (request) {
var expected = {
method: "POST",
url: "_search",
data: [simple_request.data]
};

deepEqual(request, expected);
start();
});
});


utils_test("single line request range", single_line_request.prefix, single_line_request.data, function () {
input.getCurrentRequestRange(function (range) {
Expand Down

0 comments on commit 0304b31

Please sign in to comment.