Skip to content

Commit b455f98

Browse files
committed
+invalid_template_name_types
1 parent 8d79b61 commit b455f98

6 files changed

Lines changed: 223 additions & 74 deletions

File tree

_test suite/test.js

Lines changed: 74 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2351,6 +2351,7 @@ function test_net() {
23512351
assert(["8080", (CeL.URI('http://127.0.0.1:8080')).port], 'CeL.net.URI() #3');
23522352
assert(['//www.example.com/path/to/file/', CeL.URI('//www.example.com/path/to/file/').toString()], 'CeL.net.URI() #4');
23532353
assert(['mailto:user@www.example.com', CeL.URI('mailto:user@www.example.com').toString()], 'CeL.net.URI() #5');
2354+
assert(["a.b", (CeL.URI('https://a.b/@cc/')).hostname], 'CeL.net.URI() #6');
23542355

23552356
assert(['file:///C:/d/a.htm', (new CeL.URI('a.htm', 'file:///c:/d/b.htm')).toString()], 'CeL.net.URI(, base) #1');
23562357
assert(['file:///C:/a.htm', (new CeL.URI('/a.htm', 'file:///c:/d/b.htm')).toString()], 'CeL.net.URI(, base) #2');
@@ -2362,12 +2363,12 @@ function test_net() {
23622363

23632364
var href, url, uri;
23642365
href = 'ftp://user:cgh@dr.fxgv.sfdg:4231/3452/dgh.rar?fg=23&a=2&fg2=24#hhh'; url = new URL(href); uri = new CeL.URI(href);
2365-
assert([href, uri.toString()], 'CeL.net.URI() #3-1');
2366-
assert([href, url.toString()], 'CeL.net.URI() #3-2');
2367-
assert([href, (new URL(uri)).toString()], 'CeL.net.URI() #3-3');
2368-
assert([href, (new CeL.URI(url)).toString()], 'CeL.net.URI() #3-4');
2369-
assert([uri, CeL.URI(uri)], 'CeL.net.URI() #3-5');
2370-
assert([href, CeL.URI(href).toString()], 'CeL.net.URI() #3-6');
2366+
assert([href, uri.toString()], 'CeL.net.URI() #1 of ' + href);
2367+
assert([href, url.toString()], 'CeL.net.URI() #2 of ' + href);
2368+
assert([href, (new URL(uri)).toString()], 'CeL.net.URI() #3 of ' + href);
2369+
assert([href, (new CeL.URI(url)).toString()], 'CeL.net.URI() #4 of ' + href);
2370+
assert([uri, CeL.URI(uri)], 'CeL.net.URI() #5 of ' + href);
2371+
assert([href, CeL.URI(href).toString()], 'CeL.net.URI() #6 of ' + href);
23712372

23722373
assert(['https://www.example.com/pP/qQ', CeL.URI('HTTPS://WWW.EXAMPLE.COM/pP/qQ').toString()], 'CeL.net.URI(upper case)');
23732374

@@ -2417,8 +2418,8 @@ function test_net() {
24172418
assert(["碼", uri.search_params.編], 'CeL.net.URI() #5 of ' + href);
24182419
assert(["$%24%%25%26%3D*", uri.search_params['! %20%%26%3D']], 'CeL.net.URI() #6 of ' + href);
24192420

2420-
href = 'http://a.b?道可道=非常道&a=1'; uri = new CeL.URI('http://a.b?道可道=非常道&a=1', null, { charset: 'big5' });
24212421
CeL.data.character.load("Big5");
2422+
href = 'http://a.b?道可道=非常道&a=1'; uri = new CeL.URI('http://a.b?道可道=非常道&a=1', null, { charset: 'big5' });
24222423
assert(["http://a.b?%B9D%A5i%B9D=%ABD%B1%60%B9D&a=1", uri.toString()], 'CeL.net.URI() charset encoding ' + uri.charset);
24232424

24242425
});
@@ -4266,9 +4267,9 @@ function test_wiki() {
42664267
assert(['transclusion', parsed.type], 'wiki.parse.transclusion #37-1');
42674268
assert(['parameter_unit', parsed[1].type], 'wiki.parse.transclusion #37-2');
42684269
assert([' {{_|t}} ', parsed[1].toString()], 'wiki.parse.transclusion #37-3');
4270+
// @see "{{a{{_|text}} | a }}"
42694271
wikitext = '{{ {{_|text}} | a }}'; parsed = CeL.wiki.parse(wikitext);
4270-
assert([wikitext, parsed.toString()], 'wiki.parse.transclusion #38');
4271-
assert(['plain', parsed.type], 'wiki.parse.transclusion #38-1');
4272+
assert([wikitext, parsed], 'wiki.parse.transclusion #38');
42724273
wikitext = '{{text| {{ {{_}} }} }}'; parsed = CeL.wiki.parse(wikitext);
42734274
assert([wikitext, parsed.toString()], 'wiki.parse.transclusion #39');
42744275
assert(['transclusion', parsed.type], 'wiki.parse.transclusion #39-1');
@@ -4291,31 +4292,27 @@ function test_wiki() {
42914292
assert([wikitext, parsed.toString()], 'wiki.parse.transclusion #41-5');
42924293
assert(['Template:A', parsed.page_title], 'wiki.parse.transclusion #41-6');
42934294

4294-
wikitext = '{{text| {{ {{<s> }} }} </s> }}'; parsed = CeL.wiki.parse(wikitext);
4295+
wikitext = '{{center| {{ {{<s> }} }} </s> }}'; parsed = CeL.wiki.parse(wikitext);
42954296
assert([wikitext, parsed.toString()], 'wiki.parse.transclusion #42');
42964297
assert(['transclusion', parsed.type], 'wiki.parse.transclusion #42-1');
42974298
assert(['parameter_unit', parsed[1].type], 'wiki.parse.transclusion #42-2');
42984299
var matched = undefined;
4299-
CeL.wiki.parser.parser_prototype.each.call(parsed[1][2], 'tag', function (token) { matched = token; });
4300+
CeL.wiki.parser.parser_prototype.each.call(parsed[1], 'tag', function (token) { matched = token; });
43004301
assert(['<s> }} }} </s>', matched && matched.toString()], 'wiki.parse.transclusion #42-3');
43014302

4302-
// TODO:
4303-
// "{{text| {{ {{<s>}} </s> }}"
4304-
// "{{text| {{ {{<s title="{{s}}"> }} }} </s> }}"
4305-
wikitext = '{{text| {{ {{<s>}} }}</s> }}'; parsed = CeL.wiki.parse(wikitext);
4303+
wikitext = '{{center| {{ {{<s>}} }}</s> }}'; parsed = CeL.wiki.parse(wikitext);
43064304
assert([wikitext, parsed.toString()], 'wiki.parse.transclusion #43');
43074305
assert(['transclusion', parsed.type], 'wiki.parse.transclusion #43-1');
43084306
assert(['parameter_unit', parsed[1].type], 'wiki.parse.transclusion #43-2');
43094307
var matched = undefined;
4310-
CeL.wiki.parser.parser_prototype.each.call(parsed[1][2], 'tag', function (token) { matched = token; });
4308+
CeL.wiki.parser.parser_prototype.each.call(parsed[1], 'tag', function (token) { matched = token; });
43114309
assert(['<s>}} }}</s>', matched && matched.toString()], 'wiki.parse.transclusion #43-3');
43124310

43134311
wikitext = '{{a{{_|text}} | a }}'; parsed = CeL.wiki.parse(wikitext);
4314-
assert([wikitext, parsed.toString()], 'wiki.parse.transclusion #44');
4315-
assert(['plain', parsed.type], 'wiki.parse.transclusion #44-1');
4312+
assert([wikitext, parsed], 'wiki.parse.transclusion #44');
43164313
var count = 0;
4317-
CeL.wiki.parser.parser_prototype.each.call(parsed[1][2], 'transclusion', function (token) { count++; });
4318-
assert([0, count], 'wiki.parse.transclusion #43-2');
4314+
CeL.wiki.parser.parser_prototype.each.call(parsed, 'transclusion', function (token) { count++; });
4315+
assert([0, count], 'wiki.parse.transclusion #44-2');
43194316

43204317
wikitext = '{{[[t]]}}'; parsed = CeL.wiki.parse(wikitext);
43214318
assert([wikitext, parsed.toString()], 'wiki.parse.transclusion #45');
@@ -4347,6 +4344,56 @@ function test_wiki() {
43474344
wikitext = "{{T}}{{T|1=[[A]] ''i''|2='''b''bi'''}} }}"; parsed = CeL.wiki.parse(wikitext);
43484345
assert([wikitext, parsed.toString()], 'wiki.parse.transclusion #50');
43494346

4347+
wikitext = '{{<del>}}'; parsed = CeL.wiki.parse(wikitext);
4348+
assert([wikitext, parsed.toString()], 'wiki.parse.transclusion #51');
4349+
assert(['tag', parsed[1].type], 'wiki.parse.transclusion #51-1');
4350+
assert(['<del>}}', parsed[1].toString()], 'wiki.parse.transclusion #51-2');
4351+
4352+
wikitext = '{{a<b>b</b>}}'; parsed = CeL.wiki.parse(wikitext);
4353+
assert([wikitext, parsed.toString()], 'wiki.parse.transclusion #52');
4354+
assert(['tag', parsed[1].type], 'wiki.parse.transclusion #52-1');
4355+
assert(['<b>b</b>', parsed[1].toString()], 'wiki.parse.transclusion #52-2');
4356+
4357+
wikitext = '{{[[t]]}}'; parsed = CeL.wiki.parse(wikitext);
4358+
assert([wikitext, parsed.toString()], 'wiki.parse.transclusion #53');
4359+
assert(['link', parsed[1].type], 'wiki.parse.transclusion #53-1');
4360+
assert(['[[t]]', parsed[1].toString()], 'wiki.parse.transclusion #53-2');
4361+
4362+
wikitext = '{{a{{_|text}} | a }}'; parsed = CeL.wiki.parse(wikitext);
4363+
assert([wikitext, parsed], 'wiki.parse.transclusion #54');
4364+
4365+
// TODO:
4366+
// @see '{{center| {{ {{<s> }} }} </s> }}'
4367+
wikitext = '{{center| {{ {{<s>}} </s> }}'; parsed = CeL.wiki.parse(wikitext);
4368+
assert([wikitext, parsed.toString()], 'wiki.parse.transclusion #55');
4369+
// assert(['tag', parsed[1].type], 'wiki.parse.transclusion #55-1');
4370+
// assert(['<s>}} </s>', parsed[1].toString()], 'wiki.parse.transclusion #55-2');
4371+
4372+
wikitext = '{{center| {{ {{<s>}} {{</s>}} }}'; parsed = CeL.wiki.parse(wikitext);
4373+
assert([wikitext, parsed.toString()], 'wiki.parse.transclusion #56');
4374+
// assert(['tag', parsed[1].type], 'wiki.parse.transclusion #56-1');
4375+
// assert(['<s>}} {{</s>', parsed[1].toString()], 'wiki.parse.transclusion #56-2');
4376+
4377+
wikitext = '{{center| {{ {{<s>}} }}{{</s>}}'; parsed = CeL.wiki.parse(wikitext);
4378+
assert([wikitext, parsed.toString()], 'wiki.parse.transclusion #57');
4379+
// assert(['tag', parsed[1].type], 'wiki.parse.transclusion #57-1');
4380+
// assert(['<s>}} }}{{</s>', parsed[1].toString()], 'wiki.parse.transclusion #57-2');
4381+
4382+
wikitext = '{{center| {{ {{<s>}} }}tt{{</s>}}'; parsed = CeL.wiki.parse(wikitext);
4383+
assert([wikitext, parsed.toString()], 'wiki.parse.transclusion #58');
4384+
// assert(['tag', parsed[1].type], 'wiki.parse.transclusion #58-1');
4385+
// assert(['<s>}} }}tt{{</s>', parsed[1].toString()], 'wiki.parse.transclusion #58-2');
4386+
4387+
wikitext = '{{center| {{_}} }}'; parsed = CeL.wiki.parse(wikitext);
4388+
assert([wikitext, parsed.toString()], 'wiki.parse.transclusion #59');
4389+
assert(['transclusion', parsed.type], 'wiki.parse.transclusion #59-1');
4390+
assert([' {{_}} ', parsed.parameters[1].toString()], 'wiki.parse.transclusion #59-2');
4391+
4392+
wikitext = '{{center| {{ {{<s title="{{s}}"> }} }} </s> }}'; parsed = CeL.wiki.parse(wikitext);
4393+
assert([wikitext, parsed.toString()], 'wiki.parse.transclusion #60');
4394+
assert(['transclusion', parsed.type], 'wiki.parse.transclusion #60-1');
4395+
assert([' {{ {{<s title="{{s}}"> }} }} </s> ', parsed.parameters[1].toString()], 'wiki.parse.transclusion #60-2');
4396+
43504397

43514398
wikitext = 'a[[link]]b'; parsed = CeL.wiki.parser(wikitext).parse();
43524399
assert([wikitext, parsed.toString()]);
@@ -5092,6 +5139,11 @@ function test_wiki() {
50925139
assert(['link', parsed[1][0].type], 'wiki.parse: nowiki #34-1');
50935140
assert(['nowiki', parsed[1][0][2][0].tag], 'wiki.parse: nowiki #34-2');
50945141
assert(['[b]<!-- c -->', CeL.wiki.wikitext_to_plain_text(wikitext)], 'wiki.parse: nowiki #34-3');
5142+
wikitext = '<ref>[http://a.b <nowiki>[]</nowiki>]</ref>'; parsed = CeL.wiki.parse(wikitext);
5143+
assert([wikitext, parsed.toString()], 'wiki.parse: nowiki #35');
5144+
assert(['external_link', parsed[1][0].type], 'wiki.parse: nowiki #35-1');
5145+
assert(['tag', parsed[1][0][2].type], 'wiki.parse: nowiki #35-2');
5146+
assert(['nowiki', parsed[1][0][2].tag], 'wiki.parse: nowiki #35-3');
50955147

50965148
// 2024/2/7 18:0:20 Will throw error: Uncaught RangeError: Maximum call stack size exceeded
50975149
CeL.wiki.parser('<noinclude>\n{{Documentation}}</noinclude>').parse().each(function (token) { });
@@ -5592,6 +5644,7 @@ function test_wiki() {
55925644
assert(['0', CeL.wiki.expand_transclusion('{{#expr:.}}').toString()], 'wiki.expand_transclusion: {{#expr:}} #198');
55935645
assert(['1', CeL.wiki.expand_transclusion('{{#expr:.*.+not.}}').toString()], 'wiki.expand_transclusion: {{#expr:}} #199');
55945646
assert(['123.456', CeL.wiki.expand_transclusion('{{#expr:123.456.789}}').toString()], 'wiki.expand_transclusion: {{#expr:}} #200');
5647+
// TODO
55955648
//assert(['-0', CeL.wiki.expand_transclusion('{{#expr: -0}}').toString()], 'wiki.expand_transclusion: {{#expr:}} #201');
55965649
assert(['', CeL.wiki.expand_transclusion('').toString()], 'wiki.expand_transclusion: {{#expr:}} #20');
55975650

@@ -6472,7 +6525,7 @@ function test_wiki() {
64726525
interwiki_data = CeL.wiki.parse.interwiki_link(CeL.wiki.parse(interwiki_data.wikilink), options);
64736526
assert(['ja|赤めだか', interwiki_data && interwiki_data.interlanguage && [interwiki_data.interlanguage.prefix, interwiki_data.interlanguage.title].join('|')], 'zhwiki: parse.interwiki_url() and parse.interwiki_link() #8-3');
64746527

6475-
wikitext = '[//zh.m.wikipedia.org/zh-tw/%E4%BD%A9%E5%8D%93%C2%B7%E8%B2%BB%E5%8D%97%E5%BE%B7%E8%8C%B2 威能帝]'; parsed = CeL.wiki.parse(wikitext, options); interwiki_data = CeL.wiki.parse.interwiki_url(parsed, options);
6528+
wikitext = '[//zh.m.wikipedia.org/zh-tw/{{urlencode:佩卓·費南德茲}} 威能帝]'; parsed = CeL.wiki.parse(wikitext, options); interwiki_data = CeL.wiki.parse.interwiki_url(parsed, options);
64766529
assert(['zh', interwiki_data && interwiki_data.prefix], 'zhwiki: parse.interwiki_url() and parse.interwiki_link() #9-1');
64776530
assert(['[[佩卓·費南德茲|威能帝]]', interwiki_data && interwiki_data.wikilink && interwiki_data.wikilink.toString()], 'zhwiki: parse.interwiki_url() and parse.interwiki_link() #9-2');
64786531

application/net.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ function module_code(library_namespace) {
220220

221221
// ------------------------------------------------------------------------
222222

223+
// default port of protocol
223224
var port_of_protocol = {
224225
// https://tools.ietf.org/html/rfc1928#section-3
225226
// The SOCKS service is conventionally located on TCP port 1080.
@@ -238,8 +239,8 @@ function module_code(library_namespace) {
238239

239240
var PATTERN_URI =
240241
// [ all, 1: `protocol:`, 2: '//', 3: host, 4: path ]
241-
/^([\w\-]{2,}:)?(\/\/)?(\/[A-Z]:|(?:[^@]*@)?[^\/#?&:.][^\/#?&:]+(?::\d{1,5})?)?(.*)$/i
242-
// /^(?:(https?:)\/\/)?(?:([^:@]+)(?::([^@]*))?@)?([^:@]+)(?::(\d{1,5}))?$/
242+
/^([\w\-]{2,}:)?(\/\/)?(\/[A-Z]:|(?:[^@\/]*@)?[^\/#?&:.][^\/#?&:]+(?::\d{1,5})?)?(.*)$/i
243+
// /^(?:(https?:)\/\/)?(?:([^:@\/]+)(?::([^@\/]*))?@)?([^:@\/]+)(?::(\d{1,5}))?$/
243244
;
244245

245246
/**
@@ -419,7 +420,7 @@ function module_code(library_namespace) {
419420
if (href && !/^\/[A-Z]:$/i.test(href)
420421
&& (path.charAt(0) === '/' || /[@:]/.test(href))) {
421422
// 處理 username:password
422-
if (matched = href.match(/^([^@]*)@(.+)$/)) {
423+
if (matched = href.match(/^([^@\/]*)@(.+)$/)) {
423424
matched.user_passwords = matched[1].match(/^([^:]+)(:(.*))?$/);
424425
if (!matched.user_passwords)
425426
return;
@@ -433,8 +434,9 @@ function module_code(library_namespace) {
433434
uri.username = '';
434435
}
435436

437+
// new URL('http://a. b/') 可正常處理,應允許 \s。
436438
// [ all, host, (integer)port ]
437-
matched = href.match(/^([^\/#?&\s:]+)(?::(\d{1,5}))?$/);
439+
matched = href.match(/^([^\/#?&:]+)(?::(\d{1,5}))?$/);
438440
if (!matched) {
439441
throw new Error('Invalid host: ' + href);
440442
}

application/net/wiki/parser/misc.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,11 @@ function module_code(library_namespace) {
270270
}
271271

272272
url = String(url);
273-
url = library_namespace.HTML_to_Unicode(url);
274-
275-
if (typeof options.postfix_url === 'function') {
276-
url = options.postfix_url(url);
277-
if (!url) {
278-
return;
279-
}
280-
// assert: typeof url === 'string'
273+
if (url.includes('{{')) {
274+
// [[吉胖喵]]: Invalid page title "{{urlencode:胖吉喵}}"
275+
url = wiki_API.expand_transclusion(url, options).toString();
281276
}
277+
url = library_namespace.HTML_to_Unicode(url);
282278

283279
/**
284280
* Wikimedia 網域名轉換 <code>
@@ -290,6 +286,14 @@ function module_code(library_namespace) {
290286
*/
291287
url = url.replace('//mail.wikipedia.org/', '//lists.wikimedia.org/');
292288

289+
if (typeof options.postfix_url === 'function') {
290+
url = options.postfix_url(url);
291+
if (!url) {
292+
return;
293+
}
294+
// assert: typeof url === 'string'
295+
}
296+
293297
var _url = new library_namespace.URI(url);
294298
if (!_url) {
295299
library_namespace.debug('Invalid URL: ' + url, 2,

0 commit comments

Comments
 (0)