Skip to content

Commit 4bbfbab

Browse files
SimeonCSimeonC
SimeonC
authored and
SimeonC
committed
fix(taBind._blankTest): Fix for highly nested content.
Fixes #512
1 parent 9525707 commit 4bbfbab

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

lib/taBind.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,20 @@ angular.module('textAngular.taBind', ['textAngular.factories', 'textAngular.DOM'
44
return function(_defaultTest){
55
return function(_blankVal){
66
if(!_blankVal) return true;
7-
// Don't do a global replace as that would be waaayy too long, just replace the first 4 occurences should be enough
8-
_blankVal = _blankVal.toString().replace(/="[^"]*"/i, '').replace(/="[^"]*"/i, '').replace(/="[^"]*"/i, '').replace(/="[^"]*"/i, '');
9-
var _firstTagIndex = _blankVal.indexOf('>');
10-
if(_firstTagIndex === -1) return _blankVal.trim().length === 0;
7+
// find first non-tag match - ie start of string or after tag that is not whitespace
8+
var _firstMatch = /(^[^<]|>)[^<]/i.exec(_blankVal);
9+
var _firstTagIndex;
10+
if(!_firstMatch){
11+
// find the end of the first tag removing all the
12+
// Don't do a global replace as that would be waaayy too long, just replace the first 4 occurences should be enough
13+
_blankVal = _blankVal.toString().replace(/="[^"]*"/i, '').replace(/="[^"]*"/i, '').replace(/="[^"]*"/i, '').replace(/="[^"]*"/i, '');
14+
_firstTagIndex = _blankVal.indexOf('>');
15+
}else{
16+
_firstTagIndex = _firstMatch.index;
17+
}
1118
_blankVal = _blankVal.trim().substring(_firstTagIndex, _firstTagIndex + 100);
19+
// check for no tags entry
20+
if(/^[^<>]+$/i.test(_blankVal)) return false;
1221
// this regex is to match any number of whitespace only between two tags
1322
if (_blankVal.length === 0 || _blankVal === _defaultTest || /^>(\s|&nbsp;)*<\/[^>]+>$/ig.test(_blankVal)) return true;
1423
// this regex tests if there is a tag followed by some optional whitespace and some text after that

test/taBind/taBind._taBlankTest.spec.js

+20-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,26 @@ describe('taBind._taBlankTest', function () {
2424
'<p>Test Some<br></p>',
2525
'Some Test',
2626
'<p><img class="ta-insert-video" src="https://img.youtube.com/vi/sbQQKI1Fwo4/hqdefault.jpg" ta-insert-video="https://www.youtube.com/embed/sbQQKI1Fwo4" contenteditable="false" allowfullscreen="true" frameborder="0"><br></p>',
27-
'<p></p><p style="color: rgb(68, 68, 68);text-align: left;background-color: rgb(255, 255, 255);"><u><b>ATTITUDES:</b></u></p>'
27+
'<p></p><p style="color: rgb(68, 68, 68);text-align: left;background-color: rgb(255, 255, 255);"><u><b>ATTITUDES:</b></u></p>',
28+
'<div class="AppContainer" style="width: 1280px;color: rgb(0, 0, 0);">' + // a real world case from #512
29+
'<div id="c_base" class="c_base">' +
30+
'<div id="c_content" class="c_main">' +
31+
'<div id="pageContent">' +
32+
'<div id="pageInbox" class="v-Page">' +
33+
'<div id="inboxControl0f">' +
34+
'<div class="containsYSizerBar" style="height: 849px;width: 1280px;">' +
35+
'<div class="ContentRight WithRightRail FullView">' +
36+
'<div class="ContentRightInner t_mbgc t_qtc t_urtc" style="color: rgb(68, 68, 68);background-color: rgb(255, 255, 255);">' +
37+
'<div id="inboxControl0fv-ReadMessageContainer" class="v-ReadMessageContainer slideOnResize">' +
38+
'<div class="c-ReadMessage" style="height: 818.03125px;width: 895px;">' +
39+
'<div class="rmMessages ClearBoth" id="ReadMessageScrollableSection">' +
40+
'<div id="readMessagePartControl1604f" class="c-ReadMessagePart ReadMsgContainer HasLayout ClearBoth HideShadows FullPart NoHistory Read RmIc">' +
41+
'<div class="c-ReadMessagePartBody">' +
42+
'<div class="readMsgBody">' +
43+
'<div id="bodyreadMessagePartBodyControl1609f" class="ExternalClass MsgBodyContainer">' +
44+
'<p><u><b>Lorem ipsum</b></u></p>' +
45+
'<p><b>Lorem ipsum</b></p>' +
46+
'</div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>'
2847
],
2948
testString(false)
3049
);

0 commit comments

Comments
 (0)