Skip to content

Commit 6821dee

Browse files
bebarinogitster
authored andcommitted
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 <[email protected]> Cc: Jakub Narebski <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6aa2de5 commit 6821dee

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

gitweb/gitweb.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,19 @@ function fixLinks() {
6464

6565
/**
6666
* 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)
6969
*
7070
* @param {Number|String} input: number to pad
7171
* @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'
7373
* @returns {String} INPUT prefixed with (WIDTH - INPUT.length) x STR
7474
*/
7575
function padLeftStr(input, width, str) {
7676
var prefix = '';
7777

7878
width -= input.toString().length;
79-
while (width > 1) {
79+
while (width > 0) {
8080
prefix += str;
8181
width--;
8282
}
@@ -192,7 +192,7 @@ function updateProgressInfo() {
192192

193193
if (div_progress_info) {
194194
div_progress_info.firstChild.data = blamedLines + ' / ' + totalLines +
195-
' (' + padLeftStr(percentage, 3, '&nbsp;') + '%)';
195+
' (' + padLeftStr(percentage, 3, '\u00A0') + '%)';
196196
}
197197

198198
if (div_progress_bar) {

0 commit comments

Comments
 (0)