@matheusbsbs / matheus-bagliano / commits / 6821dee9a9
Fork 0

gitweb.js: fix padLeftStr() and its usage

It seems that in Firefox-3.5 inserting &nbsp; with javascript inserts the literal &nbsp; instead of a space. Fix this by inserting the unicode representation for &nbsp; instead. Also fix the off-by-one error in the padding calculation that was causing one less space to be inserted than was requested by the caller. Signed-off-by: Stephen Boyd <bebarino@gmail.com> Cc: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stephen Boyd committed Nov 24, 2009 at 19:51 UTC 6821dee9a91131e1a003ee65b2f4218a19ea8f3d
1 file changed +5 -5
gitweb/gitweb.js
+5 -5
@@ -64,19 +64,19 @@ function fixLinks() {
64
65 /**
66 * pad number N with nonbreakable spaces on the left, to WIDTH characters
67 - * example: padLeftStr(12, 3, '&nbsp;') == '&nbsp;12'
68 - * ('&nbsp;' is nonbreakable space)
67 + * example: padLeftStr(12, 3, '\u00A0') == '\u00A012'
68 + * ('\u00A0' is nonbreakable space)
69 *
70 * @param {Number|String} input: number to pad
71 * @param {Number} width: visible width of output
72 - * @param {String} str: string to prefix to string, e.g. '&nbsp;'
72 + * @param {String} str: string to prefix to string, e.g. '\u00A0'
73 * @returns {String} INPUT prefixed with (WIDTH - INPUT.length) x STR
74 */
75 function padLeftStr(input, width, str) {
76 var prefix = '';
77
78 width -= input.toString().length;
79 - while (width > 1) {
79 + while (width > 0) {
80 prefix += str;
81 width--;
82 }
@@ -192,7 +192,7 @@ function updateProgressInfo() {
192
193 if (div_progress_info) {
194 div_progress_info.firstChild.data = blamedLines + ' / ' + totalLines +
195 - ' (' + padLeftStr(percentage, 3, '&nbsp;') + '%)';
195 + ' (' + padLeftStr(percentage, 3, '\u00A0') + '%)';
196 }
197
198 if (div_progress_bar) {