Skip to content

Commit ad69edd

Browse files
authored
Merge pull request #124 from rtfpessoa/fix-escaping-in-headers
Fix escaping in header lines
2 parents 01c0f15 + 267748f commit ad69edd

File tree

8 files changed

+523
-156
lines changed

8 files changed

+523
-156
lines changed

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,22 @@
5757
"dependencies": {
5858
"diff": "^3.2.0",
5959
"hogan.js": "^3.0.2",
60-
"whatwg-fetch": "^2.0.1"
60+
"whatwg-fetch": "^2.0.3"
6161
},
6262
"devDependencies": {
63-
"autoprefixer": "^6.6.1",
64-
"browserify": "^13.3.0",
65-
"clean-css": "^3.4.23",
66-
"codacy-coverage": "^2.0.0",
67-
"eslint": "^3.13.1",
68-
"eslint-plugin-promise": "^3.4.0",
69-
"eslint-plugin-standard": "^2.0.1",
63+
"autoprefixer": "^6.7.7",
64+
"browserify": "^14.1.0",
65+
"clean-css": "^4.0.9",
66+
"codacy-coverage": "^2.0.1",
67+
"eslint": "^3.18.0",
68+
"eslint-plugin-promise": "^3.5.0",
69+
"eslint-plugin-standard": "^2.1.1",
7070
"fast-html-parser": "^1.0.1",
7171
"istanbul": "^0.4.5",
7272
"mkdirp": "^0.5.1",
7373
"mocha": "^3.2.0",
7474
"nopt": "^4.0.1",
75-
"postcss-cli": "^2.6.0",
75+
"postcss-cli": "^3.0.0",
7676
"uglifyjs": "^2.4.10"
7777
},
7878
"license": "MIT",

scripts/release.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ rm -rf ${OUTPUT_DIR}
3131
mkdir -p ${OUTPUT_DIR}
3232

3333
echo "Minifying ${OUTPUT_CSS_FILE} to ${OUTPUT_MIN_CSS_FILE}"
34-
postcss --use autoprefixer ${INPUT_CSS_FILE} -d ${OUTPUT_DIR}
34+
postcss --use autoprefixer -o ${OUTPUT_CSS_FILE} ${INPUT_CSS_FILE}
3535
cleancss --advanced --compatibility=ie8 -o ${OUTPUT_MIN_CSS_FILE} ${OUTPUT_CSS_FILE}
3636

3737
echo "Pre-compile hogan.js templates"

src/line-by-line-printer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
LineByLinePrinter.prototype.makeColumnLineNumberHtml = function(block) {
7474
return hoganUtils.render(genericTemplatesPath, 'column-line-number', {
7575
diffParser: diffParser,
76-
blockHeader: block.header,
76+
blockHeader: utils.escape(block.header),
7777
lineClass: 'd2h-code-linenumber',
7878
contentClass: 'd2h-code-line'
7979
});

src/side-by-side-printer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
SideBySidePrinter.prototype.makeSideHtml = function(blockHeader) {
7272
return hoganUtils.render(genericTemplatesPath, 'column-line-number', {
7373
diffParser: diffParser,
74-
blockHeader: blockHeader,
74+
blockHeader: utils.escape(blockHeader),
7575
lineClass: 'd2h-code-side-linenumber',
7676
contentClass: 'd2h-code-side-line'
7777
});

src/utils.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
.replace(/&/g, '&')
1515
.replace(/</g, '&lt;')
1616
.replace(/>/g, '&gt;')
17+
.replace(/"/g, '&quot;')
18+
.replace(/'/g, '&#x27;')
19+
.replace(/\//g, '&#x2F;')
1720
.replace(/\t/g, ' ');
1821
};
1922

test/diff2html-tests.js

Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,5 +288,241 @@ describe('Diff2Html', function() {
288288
var result = Diff2Html.getPrettySideBySideHtmlFromDiff(diffExample1, {showFiles: true});
289289
assert.equal(htmlSideExample1WithFilesSummary, result);
290290
});
291+
292+
it('should generate pretty side by side html from diff with html on headers', function() {
293+
var diffExample2 = 'diff --git a/CHANGELOG.md b/CHANGELOG.md\n' +
294+
'index fc3e3f4..b486d10 100644\n' +
295+
'--- a/CHANGELOG.md\n' +
296+
'+++ b/CHANGELOG.md\n' +
297+
'@@ -1,7 +1,6 @@\n' +
298+
' # Change Log\n' +
299+
' All notable changes to this project will be documented in this file.\n' +
300+
' This project adheres to [Semantic Versioning](http://semver.org/).\n' +
301+
'-$a="<table><tr><td>Use the following format for additions: ` - VERSION: [feature/patch (if applicable)] Short description of change. Links to relevant issues/PRs.`\n' +
302+
' $a="<table><tr><td>\n' +
303+
" $a=\"<table><tr><td>- 1.1.9: Fix around ubuntu's inability to cache promises. [#877](https://github.com/FredrikNoren/ungit/pull/878)\n" +
304+
' - 1.1.8:\n' +
305+
"@@ -11,7 +10,7 @@ $a=\"<table><tr><td>- 1.1.9: Fix around ubuntu's inability to cache promises. [#8\n" +
306+
' - 1.1.7:\n' +
307+
' - Fix diff flickering issue and optimization [#865](https://github.com/FredrikNoren/ungit/pull/865)\n' +
308+
' - Fix credential dialog issue [#864](https://github.com/FredrikNoren/ungit/pull/864)\n' +
309+
'- - Fix HEAD branch order when redraw [#858](https://github.com/FredrikNoren/ungit/issues/858)\n' +
310+
'+4 - Fix HEAD branch order when redraw [#858](https://github.com/FredrikNoren/ungit/issues/858)\n' +
311+
' - 1.1.6: Fix path auto complete [#861](https://github.com/FredrikNoren/ungit/issues/861)\n' +
312+
' - 1.1.5: Update "Toggle all" button after commit or changing selected files [#859](https://github.com/FredrikNoren/ungit/issues/859)\n' +
313+
' - 1.1.4: [patch] Promise refactoring\n' +
314+
' \n';
315+
316+
var htmlExample2 = '<div class="d2h-wrapper">\n' +
317+
' <div id="d2h-211439" class="d2h-file-wrapper" data-lang="md">\n' +
318+
' <div class="d2h-file-header">\n' +
319+
' <span class="d2h-file-name-wrapper">\n' +
320+
' <span class="d2h-icon-wrapper"><svg aria-hidden="true" class="d2h-icon" height="16" version="1.1" viewBox="0 0 12 16" width="12">\n' +
321+
' <path d="M6 5H2v-1h4v1zM2 8h7v-1H2v1z m0 2h7v-1H2v1z m0 2h7v-1H2v1z m10-7.5v9.5c0 0.55-0.45 1-1 1H1c-0.55 0-1-0.45-1-1V2c0-0.55 0.45-1 1-1h7.5l3.5 3.5z m-1 0.5L8 2H1v12h10V5z"></path>\n' +
322+
'</svg></span>\n' +
323+
' <span class="d2h-file-name">CHANGELOG.md</span>\n' +
324+
' <span class="d2h-tag d2h-changed d2h-changed-tag">CHANGED</span></span>\n' +
325+
' </div>\n' +
326+
' <div class="d2h-file-diff">\n' +
327+
' <div class="d2h-code-wrapper">\n' +
328+
' <table class="d2h-diff-table">\n' +
329+
' <tbody class="d2h-diff-tbody">\n' +
330+
' <tr>\n' +
331+
' <td class="d2h-code-linenumber d2h-info"></td>\n' +
332+
' <td class="d2h-info">\n' +
333+
' <div class="d2h-code-line d2h-info">@@ -1,7 +1,6 @@</div>\n' +
334+
' </td>\n' +
335+
'</tr><tr>\n' +
336+
' <td class="d2h-code-linenumber d2h-cntx">\n' +
337+
' <div class="line-num1">1</div>\n' +
338+
'<div class="line-num2">1</div>\n' +
339+
' </td>\n' +
340+
' <td class="d2h-cntx">\n' +
341+
' <div class="d2h-code-line d2h-cntx">\n' +
342+
' <span class="d2h-code-line-prefix"> </span>\n' +
343+
' <span class="d2h-code-line-ctn"># Change Log</span>\n' +
344+
' </div>\n' +
345+
' </td>\n' +
346+
'</tr><tr>\n' +
347+
' <td class="d2h-code-linenumber d2h-cntx">\n' +
348+
' <div class="line-num1">2</div>\n' +
349+
'<div class="line-num2">2</div>\n' +
350+
' </td>\n' +
351+
' <td class="d2h-cntx">\n' +
352+
' <div class="d2h-code-line d2h-cntx">\n' +
353+
' <span class="d2h-code-line-prefix"> </span>\n' +
354+
' <span class="d2h-code-line-ctn">All notable changes to this project will be documented in this file.</span>\n' +
355+
' </div>\n' +
356+
' </td>\n' +
357+
'</tr><tr>\n' +
358+
' <td class="d2h-code-linenumber d2h-cntx">\n' +
359+
' <div class="line-num1">3</div>\n' +
360+
'<div class="line-num2">3</div>\n' +
361+
' </td>\n' +
362+
' <td class="d2h-cntx">\n' +
363+
' <div class="d2h-code-line d2h-cntx">\n' +
364+
' <span class="d2h-code-line-prefix"> </span>\n' +
365+
' <span class="d2h-code-line-ctn">This project adheres to [Semantic Versioning](http:&#x2F;&#x2F;semver.org&#x2F;).</span>\n' +
366+
' </div>\n' +
367+
' </td>\n' +
368+
'</tr><tr>\n' +
369+
' <td class="d2h-code-linenumber d2h-del">\n' +
370+
' <div class="line-num1">4</div>\n' +
371+
'<div class="line-num2"></div>\n' +
372+
' </td>\n' +
373+
' <td class="d2h-del">\n' +
374+
' <div class="d2h-code-line d2h-del">\n' +
375+
' <span class="d2h-code-line-prefix">-</span>\n' +
376+
' <span class="d2h-code-line-ctn">$a=&quot;&lt;table&gt;&lt;tr&gt;&lt;td&gt;Use the following format for additions: ` - VERSION: [feature&#x2F;patch (if applicable)] Short description of change. Links to relevant issues&#x2F;PRs.`</span>\n' +
377+
' </div>\n' +
378+
' </td>\n' +
379+
'</tr><tr>\n' +
380+
' <td class="d2h-code-linenumber d2h-cntx">\n' +
381+
' <div class="line-num1">5</div>\n' +
382+
'<div class="line-num2">4</div>\n' +
383+
' </td>\n' +
384+
' <td class="d2h-cntx">\n' +
385+
' <div class="d2h-code-line d2h-cntx">\n' +
386+
' <span class="d2h-code-line-prefix"> </span>\n' +
387+
' <span class="d2h-code-line-ctn">$a=&quot;&lt;table&gt;&lt;tr&gt;&lt;td&gt;</span>\n' +
388+
' </div>\n' +
389+
' </td>\n' +
390+
'</tr><tr>\n' +
391+
' <td class="d2h-code-linenumber d2h-cntx">\n' +
392+
' <div class="line-num1">6</div>\n' +
393+
'<div class="line-num2">5</div>\n' +
394+
' </td>\n' +
395+
' <td class="d2h-cntx">\n' +
396+
' <div class="d2h-code-line d2h-cntx">\n' +
397+
' <span class="d2h-code-line-prefix"> </span>\n' +
398+
' <span class="d2h-code-line-ctn">$a=&quot;&lt;table&gt;&lt;tr&gt;&lt;td&gt;- 1.1.9: Fix around ubuntu&#x27;s inability to cache promises. [#877](https:&#x2F;&#x2F;github.com&#x2F;FredrikNoren&#x2F;ungit&#x2F;pull&#x2F;878)</span>\n' +
399+
' </div>\n' +
400+
' </td>\n' +
401+
'</tr><tr>\n' +
402+
' <td class="d2h-code-linenumber d2h-cntx">\n' +
403+
' <div class="line-num1">7</div>\n' +
404+
'<div class="line-num2">6</div>\n' +
405+
' </td>\n' +
406+
' <td class="d2h-cntx">\n' +
407+
' <div class="d2h-code-line d2h-cntx">\n' +
408+
' <span class="d2h-code-line-prefix"> </span>\n' +
409+
' <span class="d2h-code-line-ctn">- 1.1.8:</span>\n' +
410+
' </div>\n' +
411+
' </td>\n' +
412+
'</tr>\n' +
413+
'<tr>\n' +
414+
' <td class="d2h-code-linenumber d2h-info"></td>\n' +
415+
' <td class="d2h-info">\n' +
416+
' <div class="d2h-code-line d2h-info">@@ -11,7 +10,7 @@ $a=&quot;&lt;table&gt;&lt;tr&gt;&lt;td&gt;- 1.1.9: Fix around ubuntu&#x27;s inability to cache promises. [#8</div>\n' +
417+
' </td>\n' +
418+
'</tr><tr>\n' +
419+
' <td class="d2h-code-linenumber d2h-cntx">\n' +
420+
' <div class="line-num1">11</div>\n' +
421+
'<div class="line-num2">10</div>\n' +
422+
' </td>\n' +
423+
' <td class="d2h-cntx">\n' +
424+
' <div class="d2h-code-line d2h-cntx">\n' +
425+
' <span class="d2h-code-line-prefix"> </span>\n' +
426+
' <span class="d2h-code-line-ctn">- 1.1.7:</span>\n' +
427+
' </div>\n' +
428+
' </td>\n' +
429+
'</tr><tr>\n' +
430+
' <td class="d2h-code-linenumber d2h-cntx">\n' +
431+
' <div class="line-num1">12</div>\n' +
432+
'<div class="line-num2">11</div>\n' +
433+
' </td>\n' +
434+
' <td class="d2h-cntx">\n' +
435+
' <div class="d2h-code-line d2h-cntx">\n' +
436+
' <span class="d2h-code-line-prefix"> </span>\n' +
437+
' <span class="d2h-code-line-ctn"> - Fix diff flickering issue and optimization [#865](https:&#x2F;&#x2F;github.com&#x2F;FredrikNoren&#x2F;ungit&#x2F;pull&#x2F;865)</span>\n' +
438+
' </div>\n' +
439+
' </td>\n' +
440+
'</tr><tr>\n' +
441+
' <td class="d2h-code-linenumber d2h-cntx">\n' +
442+
' <div class="line-num1">13</div>\n' +
443+
'<div class="line-num2">12</div>\n' +
444+
' </td>\n' +
445+
' <td class="d2h-cntx">\n' +
446+
' <div class="d2h-code-line d2h-cntx">\n' +
447+
' <span class="d2h-code-line-prefix"> </span>\n' +
448+
' <span class="d2h-code-line-ctn"> - Fix credential dialog issue [#864](https:&#x2F;&#x2F;github.com&#x2F;FredrikNoren&#x2F;ungit&#x2F;pull&#x2F;864)</span>\n' +
449+
' </div>\n' +
450+
' </td>\n' +
451+
'</tr><tr>\n' +
452+
' <td class="d2h-code-linenumber d2h-del">\n' +
453+
' <div class="line-num1">14</div>\n' +
454+
'<div class="line-num2"></div>\n' +
455+
' </td>\n' +
456+
' <td class="d2h-del">\n' +
457+
' <div class="d2h-code-line d2h-del">\n' +
458+
' <span class="d2h-code-line-prefix">-</span>\n' +
459+
' <span class="d2h-code-line-ctn"> - Fix HEAD branch order when redraw [#858](https:&#x2F;&#x2F;github.com&#x2F;FredrikNoren&#x2F;ungit&#x2F;issues&#x2F;858)</span>\n' +
460+
' </div>\n' +
461+
' </td>\n' +
462+
'</tr><tr>\n' +
463+
' <td class="d2h-code-linenumber d2h-ins">\n' +
464+
' <div class="line-num1"></div>\n' +
465+
'<div class="line-num2">13</div>\n' +
466+
' </td>\n' +
467+
' <td class="d2h-ins">\n' +
468+
' <div class="d2h-code-line d2h-ins">\n' +
469+
' <span class="d2h-code-line-prefix">+</span>\n' +
470+
' <span class="d2h-code-line-ctn"><ins>4</ins> - Fix HEAD branch order when redraw [#858](https:&#x2F;&#x2F;github.com&#x2F;FredrikNoren&#x2F;ungit&#x2F;issues&#x2F;858)</span>\n' +
471+
' </div>\n' +
472+
' </td>\n' +
473+
'</tr><tr>\n' +
474+
' <td class="d2h-code-linenumber d2h-cntx">\n' +
475+
' <div class="line-num1">15</div>\n' +
476+
'<div class="line-num2">14</div>\n' +
477+
' </td>\n' +
478+
' <td class="d2h-cntx">\n' +
479+
' <div class="d2h-code-line d2h-cntx">\n' +
480+
' <span class="d2h-code-line-prefix"> </span>\n' +
481+
' <span class="d2h-code-line-ctn">- 1.1.6: Fix path auto complete [#861](https:&#x2F;&#x2F;github.com&#x2F;FredrikNoren&#x2F;ungit&#x2F;issues&#x2F;861)</span>\n' +
482+
' </div>\n' +
483+
' </td>\n' +
484+
'</tr><tr>\n' +
485+
' <td class="d2h-code-linenumber d2h-cntx">\n' +
486+
' <div class="line-num1">16</div>\n' +
487+
'<div class="line-num2">15</div>\n' +
488+
' </td>\n' +
489+
' <td class="d2h-cntx">\n' +
490+
' <div class="d2h-code-line d2h-cntx">\n' +
491+
' <span class="d2h-code-line-prefix"> </span>\n' +
492+
' <span class="d2h-code-line-ctn">- 1.1.5: Update &quot;Toggle all&quot; button after commit or changing selected files [#859](https:&#x2F;&#x2F;github.com&#x2F;FredrikNoren&#x2F;ungit&#x2F;issues&#x2F;859)</span>\n' +
493+
' </div>\n' +
494+
' </td>\n' +
495+
'</tr><tr>\n' +
496+
' <td class="d2h-code-linenumber d2h-cntx">\n' +
497+
' <div class="line-num1">17</div>\n' +
498+
'<div class="line-num2">16</div>\n' +
499+
' </td>\n' +
500+
' <td class="d2h-cntx">\n' +
501+
' <div class="d2h-code-line d2h-cntx">\n' +
502+
' <span class="d2h-code-line-prefix"> </span>\n' +
503+
' <span class="d2h-code-line-ctn">- 1.1.4: [patch] Promise refactoring</span>\n' +
504+
' </div>\n' +
505+
' </td>\n' +
506+
'</tr><tr>\n' +
507+
' <td class="d2h-code-linenumber d2h-cntx">\n' +
508+
' <div class="line-num1">18</div>\n' +
509+
'<div class="line-num2">17</div>\n' +
510+
' </td>\n' +
511+
' <td class="d2h-cntx">\n' +
512+
' <div class="d2h-code-line d2h-cntx">\n' +
513+
' <span class="d2h-code-line-prefix"> </span>\n' +
514+
' </div>\n' +
515+
' </td>\n' +
516+
'</tr>\n' +
517+
' </tbody>\n' +
518+
' </table>\n' +
519+
' </div>\n' +
520+
' </div>\n' +
521+
'</div>\n' +
522+
'</div>';
523+
524+
var result = Diff2Html.getPrettyHtmlFromDiff(diffExample2);
525+
assert.equal(result, htmlExample2);
526+
});
291527
});
292528
});

test/utils-tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('Utils', function() {
1818
});
1919
it('should escape a string with multiple problematic characters', function() {
2020
var result = Utils.escape('<a href="#">\tlink text</a>');
21-
var expected = '&lt;a href="#"&gt; link text&lt;/a&gt;';
21+
var expected = '&lt;a href=&quot;#&quot;&gt; link text&lt;&#x2F;a&gt;';
2222
assert.equal(expected, result);
2323
});
2424
});

0 commit comments

Comments
 (0)