Permalink
Browse files

fix(taFixChrome, taFixChrome.spec): corrected a bug introduced when c…

…orrecting pasted html (see PR #1411)
  • Loading branch information...
1 parent 7a23913 commit 35be0a001130b0bc621653a8ce6d4b980e733ae9 @JoelParke JoelParke committed Dec 5, 2016
Showing with 12 additions and 5 deletions.
  1. +4 −5 src/factories.js
  2. +8 −0 test/taFixChrome.spec.js
View
@@ -77,11 +77,8 @@ angular.module('textAngular.factories', [])
/////////////////////////////////////////////////////////////
if (!keepStyles) {
while (match = betterSpanMatch.exec(html)) {
- //console.log('matched string:', match[0], 'before:', html.substring(lastIndex, match.index-1));
- finalHtml += html.substring(lastIndex, match.index - 1);
- lastIndex += match.index;
+ finalHtml += html.substring(lastIndex, match.index-1);
styleVal = match[0];
- lastIndex += match[0].length;
// test for chrome inserted junk
match = /font-family: inherit;|line-height: 1.[0-9]{3,12};|color: inherit; line-height: 1.1;|color: rgb\(\d{1,3}, \d{1,3}, \d{1,3}\);|background-color: rgb\(\d{1,3}, \d{1,3}, \d{1,3}\);/gi.exec(styleVal);
if (match) {
@@ -93,14 +90,16 @@ angular.module('textAngular.factories', [])
} else {
finalHtml += ' ' + styleVal;
}
+ lastIndex = betterSpanMatch.lastIndex;
}
finalHtml += html.substring(lastIndex);
}
//console.log('final:', finalHtml);
// only replace when something has changed, else we get focus problems on inserting lists
if(lastIndex > 0){
// replace all empty strings
- return finalHtml.replace(/<span\s?>(.*?)<\/span>(<br(\/|)>|)/ig, '$1');
+ var fe = finalHtml.replace(/<span\s?>(.*?)<\/span>(<br(\/|)>|)/ig, '$1');
+ return fe;
} else return html;
};
return taFixChrome;
@@ -43,5 +43,13 @@ describe('taFixChrome', function(){
it('should keep styles', function(){
expect(taFixChrome('<div><span style="font-family: inherit; line-height: 1.428571429;">Test Content</span></div>', true)).toBe('<div><span style="font-family: inherit; line-height: 1.428571429;">Test Content</span></div>');
});
+
+ it('should handle multiple styles', function(){
+ expect(
+ taFixChrome('<pre class="command-line" style="text-align: left;"><span class="command">git checkout master</span><span>git fetch upstream</span>git merge upstream/master</pre><pre class="command-line" style="text-align: left;">git push</pre>', false))
+ .toBe(
+ '<pre class="command-line" style="text-align: left;"><span class="command">git checkout master</span>git fetch upstreamgit merge upstream/master</pre><pre class="command-line" style="text-align: left;">git push</pre>');
+ });
+
});
});

0 comments on commit 35be0a0

Please sign in to comment.