Skip to content

Commit 57ff7ba

Browse files
SimeonCSimeonC
SimeonC
authored and
SimeonC
committed
fix(taBind): _blankTest should be more performant now and stop crashing chrome
Fixes #451
1 parent b764f76 commit 57ff7ba

File tree

4 files changed

+58
-12
lines changed

4 files changed

+58
-12
lines changed

dist/textAngular.min.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/taBind.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ angular.module('textAngular.taBind', ['textAngular.factories', 'textAngular.DOM'
2020
// defaults to the paragraph element, but we need the line-break or it doesn't allow you to type into the empty element
2121
// non IE is '<p><br/></p>', ie is '<p></p>' as for once IE gets it correct...
2222
var _defaultVal, _defaultTest;
23-
var _trimTest = /^<[^>]+>(\s|&nbsp;)*<\/[^>]+>$/ig;
2423
// set the default to be a paragraph value
2524
if(attrs.taDefaultWrap === undefined) attrs.taDefaultWrap = 'p';
2625
/* istanbul ignore next: ie specific test */
@@ -41,9 +40,14 @@ angular.module('textAngular.taBind', ['textAngular.factories', 'textAngular.DOM'
4140
}
4241

4342
var _blankTest = function(_blankVal){
44-
_blankVal = _blankVal.trim();
45-
return (_blankVal.length === 0 || _blankVal === _defaultTest || _trimTest.test(_blankVal) ||
46-
!(/>\s*(([^\s<]+)\s*)+</i.test(_blankVal) || /^([^\s<>]+\s*)+$/i.test(_blankVal) || INLINETAGS_NONBLANK.test(_blankVal)));// this regex tests if there is some content that isn't white space between tags, or there is just some text passed in
43+
var _firstTagIndex = _blankVal.indexOf('>');
44+
if(_firstTagIndex === -1) return _blankVal.trim().length === 0;
45+
_blankVal = _blankVal.trim().substring(_firstTagIndex, _firstTagIndex + 100);
46+
// this regex is to match any number of whitespace only between two tags
47+
if (_blankVal.length === 0 || _blankVal === _defaultTest || /^>(\s|&nbsp;)*<\/[^>]+>$/ig.test(_blankVal)) return true;
48+
// this regex tests if there is a tag followed by some optional whitespace and some text after that
49+
else if (/>\s*[^\s<]/i.test(_blankVal) || INLINETAGS_NONBLANK.test(_blankVal)) return false;
50+
else return true;
4751
};
4852

4953
element.addClass('ta-bind');

src/textAngular.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
@license textAngular
33
Author : Austin Anderson
44
License : 2013 MIT
5-
Version 1.3.0-pre14
5+
Version 1.3.0-pre15
66
77
See README.md or https://github.com/fraywing/textAngular/wiki for requirements and use.
88
*/
@@ -758,7 +758,6 @@ angular.module('textAngular.taBind', ['textAngular.factories', 'textAngular.DOM'
758758
// defaults to the paragraph element, but we need the line-break or it doesn't allow you to type into the empty element
759759
// non IE is '<p><br/></p>', ie is '<p></p>' as for once IE gets it correct...
760760
var _defaultVal, _defaultTest;
761-
var _trimTest = /^<[^>]+>(\s|&nbsp;)*<\/[^>]+>$/ig;
762761
// set the default to be a paragraph value
763762
if(attrs.taDefaultWrap === undefined) attrs.taDefaultWrap = 'p';
764763
/* istanbul ignore next: ie specific test */
@@ -779,9 +778,14 @@ angular.module('textAngular.taBind', ['textAngular.factories', 'textAngular.DOM'
779778
}
780779

781780
var _blankTest = function(_blankVal){
782-
_blankVal = _blankVal.trim();
783-
return (_blankVal.length === 0 || _blankVal === _defaultTest || _trimTest.test(_blankVal) ||
784-
!(/>\s*(([^\s<]+)\s*)+</i.test(_blankVal) || /^([^\s<>]+\s*)+$/i.test(_blankVal) || INLINETAGS_NONBLANK.test(_blankVal)));// this regex tests if there is some content that isn't white space between tags, or there is just some text passed in
781+
var _firstTagIndex = _blankVal.indexOf('>');
782+
if(_firstTagIndex === -1) return _blankVal.trim().length === 0;
783+
_blankVal = _blankVal.trim().substring(_firstTagIndex, _firstTagIndex + 100);
784+
// this regex is to match any number of whitespace only between two tags
785+
if (_blankVal.length === 0 || _blankVal === _defaultTest || /^>(\s|&nbsp;)*<\/[^>]+>$/ig.test(_blankVal)) return true;
786+
// this regex tests if there is a tag followed by some optional whitespace and some text after that
787+
else if (/>\s*[^\s<]/i.test(_blankVal) || INLINETAGS_NONBLANK.test(_blankVal)) return false;
788+
else return true;
785789
};
786790

787791
element.addClass('ta-bind');

test/taBind/taBind.spec.js

+38
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)