Skip to content

Commit

Permalink
fix(taBind._blankTest): Fix for highly nested content.
Browse files Browse the repository at this point in the history
Fixes #512
  • Loading branch information
SimeonC authored and SimeonC committed Jan 27, 2015
1 parent 9525707 commit 4bbfbab
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
17 changes: 13 additions & 4 deletions lib/taBind.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@ angular.module('textAngular.taBind', ['textAngular.factories', 'textAngular.DOM'
return function(_defaultTest){
return function(_blankVal){
if(!_blankVal) return true;
// Don't do a global replace as that would be waaayy too long, just replace the first 4 occurences should be enough
_blankVal = _blankVal.toString().replace(/="[^"]*"/i, '').replace(/="[^"]*"/i, '').replace(/="[^"]*"/i, '').replace(/="[^"]*"/i, '');
var _firstTagIndex = _blankVal.indexOf('>');
if(_firstTagIndex === -1) return _blankVal.trim().length === 0;
// find first non-tag match - ie start of string or after tag that is not whitespace
var _firstMatch = /(^[^<]|>)[^<]/i.exec(_blankVal);
var _firstTagIndex;
if(!_firstMatch){
// find the end of the first tag removing all the
// Don't do a global replace as that would be waaayy too long, just replace the first 4 occurences should be enough
_blankVal = _blankVal.toString().replace(/="[^"]*"/i, '').replace(/="[^"]*"/i, '').replace(/="[^"]*"/i, '').replace(/="[^"]*"/i, '');
_firstTagIndex = _blankVal.indexOf('>');
}else{
_firstTagIndex = _firstMatch.index;
}
_blankVal = _blankVal.trim().substring(_firstTagIndex, _firstTagIndex + 100);
// check for no tags entry
if(/^[^<>]+$/i.test(_blankVal)) return false;
// this regex is to match any number of whitespace only between two tags
if (_blankVal.length === 0 || _blankVal === _defaultTest || /^>(\s|&nbsp;)*<\/[^>]+>$/ig.test(_blankVal)) return true;
// this regex tests if there is a tag followed by some optional whitespace and some text after that
Expand Down
21 changes: 20 additions & 1 deletion test/taBind/taBind._taBlankTest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,26 @@ describe('taBind._taBlankTest', function () {
'<p>Test Some<br></p>',
'Some Test',
'<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>',
'<p></p><p style="color: rgb(68, 68, 68);text-align: left;background-color: rgb(255, 255, 255);"><u><b>ATTITUDES:</b></u></p>'
'<p></p><p style="color: rgb(68, 68, 68);text-align: left;background-color: rgb(255, 255, 255);"><u><b>ATTITUDES:</b></u></p>',
'<div class="AppContainer" style="width: 1280px;color: rgb(0, 0, 0);">' + // a real world case from #512
'<div id="c_base" class="c_base">' +
'<div id="c_content" class="c_main">' +
'<div id="pageContent">' +
'<div id="pageInbox" class="v-Page">' +
'<div id="inboxControl0f">' +
'<div class="containsYSizerBar" style="height: 849px;width: 1280px;">' +
'<div class="ContentRight WithRightRail FullView">' +
'<div class="ContentRightInner t_mbgc t_qtc t_urtc" style="color: rgb(68, 68, 68);background-color: rgb(255, 255, 255);">' +
'<div id="inboxControl0fv-ReadMessageContainer" class="v-ReadMessageContainer slideOnResize">' +
'<div class="c-ReadMessage" style="height: 818.03125px;width: 895px;">' +
'<div class="rmMessages ClearBoth" id="ReadMessageScrollableSection">' +
'<div id="readMessagePartControl1604f" class="c-ReadMessagePart ReadMsgContainer HasLayout ClearBoth HideShadows FullPart NoHistory Read RmIc">' +
'<div class="c-ReadMessagePartBody">' +
'<div class="readMsgBody">' +
'<div id="bodyreadMessagePartBodyControl1609f" class="ExternalClass MsgBodyContainer">' +
'<p><u><b>Lorem ipsum</b></u></p>' +
'<p><b>Lorem ipsum</b></p>' +
'</div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>'
],
testString(false)
);
Expand Down

0 comments on commit 4bbfbab

Please sign in to comment.