Skip to content

Commit

Permalink
fix parsing empty strings
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Feb 24, 2018
1 parent 29b512c commit b65b506
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -13,6 +13,7 @@
* fix for wide characters inside bigger text [#369](https://github.com/jcubic/jquery.terminal/issues/369)
* when clicking on terminal and it already had focus the textarea was blured
[#370](https://github.com/jcubic/jquery.terminal/issues/370)
* fix parsing empty strings "" or ''

## 1.11.4
* handle non string and functions in error the same as in echo
Expand Down
8 changes: 6 additions & 2 deletions js/jquery.terminal-1.11.4.js
Expand Up @@ -32,7 +32,7 @@
* Copyright (c) 2007-2013 Alexandru Marasteanu <hello at alexei dot ro>
* licensed under 3 clause BSD license
*
* Date: Sat, 24 Feb 2018 10:40:25 +0000
* Date: Sat, 24 Feb 2018 11:08:16 +0000
*/

/* TODO:
Expand Down Expand Up @@ -2864,7 +2864,7 @@
}
$.terminal = {
version: 'DEV',
date: 'Sat, 24 Feb 2018 10:40:25 +0000',
date: 'Sat, 24 Feb 2018 11:08:16 +0000',
// colors from http://www.w3.org/wiki/CSS/Properties/color/keywords
color_names: [
'transparent', 'currentcolor', 'black', 'silver', 'gray', 'white',
Expand Down Expand Up @@ -3516,6 +3516,10 @@
// we don't remove slases becuase they are handled by JSON.parse
//string = string.replace(/([^\\])['"]$/, '$1');
if (string.match(/^['"]/)) {
// fixing regex to match empty string is not worth it
if (string === '""' || string === "''") {
return '';
}
var quote = string[0];
var re = new RegExp("((^|[^\\\\])(?:\\\\\\\\)*)" + quote, "g");
string = string.replace(re, "$1");
Expand Down
4 changes: 2 additions & 2 deletions js/jquery.terminal-1.11.4.min.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions js/jquery.terminal-src.js
Expand Up @@ -3516,6 +3516,10 @@
// we don't remove slases becuase they are handled by JSON.parse
//string = string.replace(/([^\\])['"]$/, '$1');
if (string.match(/^['"]/)) {
// fixing regex to match empty string is not worth it
if (string === '""' || string === "''") {
return '';
}
var quote = string[0];
var re = new RegExp("((^|[^\\\\])(?:\\\\\\\\)*)" + quote, "g");
string = string.replace(re, "$1");
Expand Down
8 changes: 6 additions & 2 deletions js/jquery.terminal.js
Expand Up @@ -32,7 +32,7 @@
* Copyright (c) 2007-2013 Alexandru Marasteanu <hello at alexei dot ro>
* licensed under 3 clause BSD license
*
* Date: Sat, 24 Feb 2018 10:40:25 +0000
* Date: Sat, 24 Feb 2018 11:08:16 +0000
*/

/* TODO:
Expand Down Expand Up @@ -2864,7 +2864,7 @@
}
$.terminal = {
version: 'DEV',
date: 'Sat, 24 Feb 2018 10:40:25 +0000',
date: 'Sat, 24 Feb 2018 11:08:16 +0000',
// colors from http://www.w3.org/wiki/CSS/Properties/color/keywords
color_names: [
'transparent', 'currentcolor', 'black', 'silver', 'gray', 'white',
Expand Down Expand Up @@ -3516,6 +3516,10 @@
// we don't remove slases becuase they are handled by JSON.parse
//string = string.replace(/([^\\])['"]$/, '$1');
if (string.match(/^['"]/)) {
// fixing regex to match empty string is not worth it
if (string === '""' || string === "''") {
return '';
}
var quote = string[0];
var re = new RegExp("((^|[^\\\\])(?:\\\\\\\\)*)" + quote, "g");
string = string.replace(re, "$1");
Expand Down
4 changes: 2 additions & 2 deletions js/jquery.terminal.min.js

Large diffs are not rendered by default.

24 changes: 14 additions & 10 deletions spec/terminalSpec.js
Expand Up @@ -172,8 +172,8 @@ var support_animations = (function() {
})();
function tests_on_ready() {
describe('Terminal utils', function() {
var command = 'test "foo bar" baz /^asd [x]/ str\\ str 10 1e10';
var args = '"foo bar" baz /^asd [x]/ str\\ str 10 1e10';
var command = 'test "foo bar" baz /^asd [x]/ str\\ str 10 1e10 ""';
var args = '"foo bar" baz /^asd [x]/ str\\ str 10 1e10 ""';
describe('$.terminal.split_arguments', function() {
it('should create array of arguments', function() {
expect($.terminal.split_arguments(args)).toEqual([
Expand All @@ -182,7 +182,8 @@ function tests_on_ready() {
'/^asd [x]/',
'str str',
'10',
'1e10'
'1e10',
''
]);
});
});
Expand All @@ -194,7 +195,8 @@ function tests_on_ready() {
/^asd [x]/,
'str str',
10,
1e10
1e10,
''
]);
});
});
Expand All @@ -210,10 +212,11 @@ function tests_on_ready() {
'/^asd [x]/',
'str str',
'10',
'1e10'
'1e10',
''
],
args_quotes: ['"', '', '', '', '', ''],
rest: '"foo bar" baz /^asd [x]/ str\\ str 10 1e10'
args_quotes: ['"', '', '', '', '', '', '"'],
rest: '"foo bar" baz /^asd [x]/ str\\ str 10 1e10 ""'
});
});
});
Expand All @@ -229,10 +232,11 @@ function tests_on_ready() {
/^asd [x]/,
'str str',
10,
1e10
1e10,
''
],
args_quotes: ['"', '', '', '', '', ''],
rest: '"foo bar" baz /^asd [x]/ str\\ str 10 1e10'
args_quotes: ['"', '', '', '', '', '', '"'],
rest: '"foo bar" baz /^asd [x]/ str\\ str 10 1e10 ""'
});
});
});
Expand Down

0 comments on commit b65b506

Please sign in to comment.