Skip to content

Commit 4388984

Browse files
committed
fix FORMATNUM
1 parent 0dea6e1 commit 4388984

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

_test suite/test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4920,6 +4920,7 @@ function test_wiki() {
49204920
assert(['987654321.654321', CeL.wiki.expand_transclusion('{{formatnum:987,654,321.654321|R}}').toString()], 'wiki.expand_transclusion: {{formatnum:}} #2');
49214921
assert(['987654321.654321', CeL.wiki.expand_transclusion('{{formatnum:{{formatnum:987654321.654321}}|R}}').toString()], 'wiki.expand_transclusion: {{formatnum:}} #3');
49224922
assert(['987654321.654321', CeL.wiki.expand_transclusion('{{formatnum:987654321.654321 |NOSEP}}').toString()], 'wiki.expand_transclusion: {{formatnum:}} #4');
4923+
assert(['10000000000000001', CeL.wiki.expand_transclusion('{{formatnum:10000000000000001|LOSSLESS}}').toString()], 'wiki.expand_transclusion: {{formatnum:}} #5');
49234924
assert(['2009 December 25', CeL.wiki.expand_transclusion('{{#dateformat:25 dec 2009|ymd}}').toString()], 'wiki.expand_transclusion: {{#formatdate:}} #1');
49244925
assert(['25 December 2009', CeL.wiki.expand_transclusion('{{#formatdate:dec 25,2009|dmy}}').toString()], 'wiki.expand_transclusion: {{#formatdate:}} #2');
49254926
assert(['December 25, 2009', CeL.wiki.expand_transclusion('{{#dateformat:2009-12-25|mdy}}').toString()], 'wiki.expand_transclusion: {{#formatdate:}} #3');

application/net/wiki/parser/evaluate.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,16 +1427,22 @@ function module_code(library_namespace) {
14271427
var number = get_parameter_String(1);
14281428
var type = get_parameter_String(2);
14291429

1430-
var matched = number.match(/^([\s\S]+?)\.(.+)?$/);
1430+
if (type === 'LOSSLESS') {
1431+
return number;
1432+
}
1433+
1434+
var matched = number.match(/^([\s\S]+?)\.(.+)?$/)
1435+
|| number.match(/^([\d,]+?)(?:\.(\d*))?$/);
14311436
if (!matched) {
14321437
// e.g.,
14331438
// '{{formatnum:abs({{#invoke:String|str_find|source=Wikipedia:互助客栈/其他|:}})-1}}'
14341439
return NYI();
14351440
}
14361441

14371442
// TODO: 此為有缺陷的極精簡版。
1438-
if (type === 'R' || type === 'NOSEP')
1443+
if (type === 'R' || type === 'NOSEP') {
14391444
return number.replace(/,/g, '');
1445+
}
14401446

14411447
var thousands_separator = THOUSANDS_SEPARATOR[wiki_API.language]
14421448
|| THOUSANDS_SEPARATOR.ISO;

0 commit comments

Comments
 (0)