Fix #1483; time parsing with padding modifier.

This commit is contained in:
Jason Davies 2013-08-23 18:51:59 +01:00
Родитель f59fc64a20
Коммит 8f4d0ac3ac
4 изменённых файлов: 12 добавлений и 5 удалений

5
d3.js поставляемый
Просмотреть файл

@ -8531,12 +8531,13 @@ d3 = function() {
return format;
}
function d3_time_parse(date, template, string, j) {
var c, p, i = 0, n = template.length, m = string.length;
var c, p, t, i = 0, n = template.length, m = string.length;
while (i < n) {
if (j >= m) return -1;
c = template.charCodeAt(i++);
if (c === 37) {
p = d3_time_parsers[template.charAt(i++)];
t = template.charAt(i++);
p = d3_time_parsers[t === "0" || t === "_" || t === "-" ? template.charAt(i++) : t];
if (!p || (j = p(date, string, j)) < 0) return -1;
} else if (c != string.charCodeAt(j++)) {
return -1;

4
d3.min.js поставляемый

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -60,6 +60,7 @@ function d3_time_format(template) {
function d3_time_parse(date, template, string, j) {
var c,
p,
t,
i = 0,
n = template.length,
m = string.length;
@ -67,7 +68,8 @@ function d3_time_parse(date, template, string, j) {
if (j >= m) return -1;
c = template.charCodeAt(i++);
if (c === 37) {
p = d3_time_parsers[template.charAt(i++)];
t = template.charAt(i++);
p = d3_time_parsers[t === "0" || t === "_" || t === "-" ? template.charAt(i++) : t];
if (!p || ((j = p(date, string, j)) < 0)) return -1;
} else if (c != string.charCodeAt(j++)) {
return -1;

Просмотреть файл

@ -284,6 +284,10 @@ suite.addBatch({
assert.deepEqual(p("% 02/03/1991"), local(1991, 1, 3));
assert.isNull(p("%% 03/10/2010"));
},
"parses padding modifier": function(format) {
var p = format("%-m/%0d/%_Y").parse;
assert.deepEqual(p("01/ 1/1990"), local(1990, 0, 1));
},
"doesn't crash when given weird strings": function(format) {
try {
Object.prototype.foo = 10;