Reject invalid autolabel counters [#48]
This commit is contained in:
parent
8397810c12
commit
e4ee5cb2ef
|
@ -1612,6 +1612,7 @@ define('sequence/LabelPatternParser',[],() => {
|
|||
let start = 1;
|
||||
let inc = 1;
|
||||
let dp = 0;
|
||||
|
||||
if(args[0]) {
|
||||
start = Number(args[0]);
|
||||
dp = Math.max(dp, countDP(args[0]));
|
||||
|
@ -1620,6 +1621,11 @@ define('sequence/LabelPatternParser',[],() => {
|
|||
inc = Number(args[1]);
|
||||
dp = Math.max(dp, countDP(args[1]));
|
||||
}
|
||||
|
||||
if(Number.isNaN(start) || Number.isNaN(inc)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {start, inc, dp};
|
||||
}
|
||||
|
||||
|
@ -1639,11 +1645,12 @@ define('sequence/LabelPatternParser',[],() => {
|
|||
args = token.substr(p + 1).split(',');
|
||||
}
|
||||
|
||||
let result = null;
|
||||
if(type === 'inc') {
|
||||
return parseCounter(args);
|
||||
result = parseCounter(args);
|
||||
}
|
||||
|
||||
return '<' + token + '>';
|
||||
return result || ('<' + token + '>');
|
||||
}
|
||||
|
||||
function parsePattern(raw) {
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -16,6 +16,7 @@ define(() => {
|
|||
let start = 1;
|
||||
let inc = 1;
|
||||
let dp = 0;
|
||||
|
||||
if(args[0]) {
|
||||
start = Number(args[0]);
|
||||
dp = Math.max(dp, countDP(args[0]));
|
||||
|
@ -24,6 +25,11 @@ define(() => {
|
|||
inc = Number(args[1]);
|
||||
dp = Math.max(dp, countDP(args[1]));
|
||||
}
|
||||
|
||||
if(Number.isNaN(start) || Number.isNaN(inc)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {start, inc, dp};
|
||||
}
|
||||
|
||||
|
@ -43,11 +49,12 @@ define(() => {
|
|||
args = token.substr(p + 1).split(',');
|
||||
}
|
||||
|
||||
let result = null;
|
||||
if(type === 'inc') {
|
||||
return parseCounter(args);
|
||||
result = parseCounter(args);
|
||||
}
|
||||
|
||||
return '<' + token + '>';
|
||||
return result || ('<' + token + '>');
|
||||
}
|
||||
|
||||
function parsePattern(raw) {
|
||||
|
|
|
@ -73,6 +73,15 @@ defineDescribe('Label Pattern Parser', ['./LabelPatternParser'], (parser) => {
|
|||
]);
|
||||
});
|
||||
|
||||
it('passes invalid counters through unchanged', () => {
|
||||
expect(parser('<inc abc>')).toEqual([
|
||||
'<inc abc>',
|
||||
]);
|
||||
expect(parser('<inc 1, abc>')).toEqual([
|
||||
'<inc 1, abc>',
|
||||
]);
|
||||
});
|
||||
|
||||
it('assigns decimal places to counters by their written precision', () => {
|
||||
const parsed = parser('<inc 5.0, 2.00><inc 2.00, 1.0>');
|
||||
expect(parsed).toEqual([
|
||||
|
|
Loading…
Reference in New Issue