Skip to content

Commit dfb841a

Browse files
Encode article title in WikiWho API access
The article title is not URL encoded when the WikiWho API URL is being constructed (Api.js#getAjaxURL). This causes any article with a question mark to have a URL containing query parameters starting wherever the question mark is.
1 parent b46af9f commit dfb841a

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/Api.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class Api {
126126
this.url,
127127
subdomain,
128128
'whocolor/v1.0.0-beta',
129-
this.mwConfig.get( 'wgPageName' ),
129+
encodeURIComponent( this.mwConfig.get( 'wgPageName' ) ),
130130
// Always include the revision ID, to make sure we are always asking for
131131
// the correct revision, whether the page was just edited, or, whether the
132132
// page was edited by someone else while we were looking at the current page

test/suite/Api.test.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe( 'Api test', () => {
1212
wgRevisionId: 234,
1313
wgPageName: 'Iñtërnâtiônàlizætiøn_(disambig)'
1414
},
15-
expected: 'https://wikiwho.example.com/en/whocolor/v1.0.0-beta/Iñtërnâtiônàlizætiøn_(disambig)/234/'
15+
expected: 'https://wikiwho.example.com/en/whocolor/v1.0.0-beta/I%C3%B1t%C3%ABrn%C3%A2ti%C3%B4n%C3%A0liz%C3%A6ti%C3%B8n_(disambig)/234/'
1616
},
1717
{
1818
msg: 'Should only append a revision ID if it is not the current one',
@@ -32,6 +32,15 @@ describe( 'Api test', () => {
3232
wgCurRevisionId: 456
3333
},
3434
expected: 'https://wikiwho.example.com/ru/whocolor/v1.0.0-beta/Foo/123/'
35+
},
36+
{
37+
msg: 'Should encode query parameters',
38+
config: {
39+
wgServerName: 'en.wikipedia.org',
40+
wgRevisionId: 123,
41+
wgPageName: 'Test Works?user-ip=0.0.0.0&'
42+
},
43+
expected: 'https://wikiwho.example.com/en/whocolor/v1.0.0-beta/Test%20Works%3Fuser-ip%3D0.0.0.0%26/123/'
3544
}
3645
];
3746

0 commit comments

Comments
 (0)