Skip to content

Commit

Permalink
fix(taBind._blankTest): Fix a bug where the first tag had really big …
Browse files Browse the repository at this point in the history
…attributes and cut off the actual content

Fixes #484
  • Loading branch information
SimeonC authored and SimeonC committed Jan 12, 2015
1 parent 3d748b0 commit fe800b2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dist/textAngular.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion lib/taBind.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ angular.module('textAngular.taBind', ['textAngular.factories', 'textAngular.DOM'
return function(_defaultTest){
return function(_blankVal){
if(!_blankVal) return true;
_blankVal = _blankVal.toString();
// 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;
_blankVal = _blankVal.trim().substring(_firstTagIndex, _firstTagIndex + 100);
Expand Down
3 changes: 2 additions & 1 deletion src/textAngular.js
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,8 @@ angular.module('textAngular.taBind', ['textAngular.factories', 'textAngular.DOM'
return function(_defaultTest){
return function(_blankVal){
if(!_blankVal) return true;
_blankVal = _blankVal.toString();
// 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;
_blankVal = _blankVal.trim().substring(_firstTagIndex, _firstTagIndex + 100);
Expand Down
8 changes: 7 additions & 1 deletion test/taBind/taBind._taBlankTest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ describe('taBind._taBlankTest', function () {

describe('should return false for', function () {
angular.forEach(
['<p>test</p>','<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>test</p>',
'<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>'
],
testString(false)
);
});
Expand Down

0 comments on commit fe800b2

Please sign in to comment.