Skip to content

Commit

Permalink
Encode article title in WikiWho API access (#188)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ChlodAlejandro authored Apr 2, 2024
1 parent b46af9f commit 677269a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class Api {
this.url,
subdomain,
'whocolor/v1.0.0-beta',
this.mwConfig.get( 'wgPageName' ),
encodeURIComponent( this.mwConfig.get( 'wgPageName' ) ),
// Always include the revision ID, to make sure we are always asking for
// the correct revision, whether the page was just edited, or, whether the
// page was edited by someone else while we were looking at the current page
Expand Down
11 changes: 10 additions & 1 deletion test/suite/Api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe( 'Api test', () => {
wgRevisionId: 234,
wgPageName: 'Iñtërnâtiônàlizætiøn_(disambig)'
},
expected: 'https://wikiwho.example.com/en/whocolor/v1.0.0-beta/Iñtërnâtiônàlizætiøn_(disambig)/234/'
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/'
},
{
msg: 'Should only append a revision ID if it is not the current one',
Expand All @@ -32,6 +32,15 @@ describe( 'Api test', () => {
wgCurRevisionId: 456
},
expected: 'https://wikiwho.example.com/ru/whocolor/v1.0.0-beta/Foo/123/'
},
{
msg: 'Should encode query parameters',
config: {
wgServerName: 'en.wikipedia.org',
wgRevisionId: 123,
wgPageName: 'Test Works?user-ip=0.0.0.0&'
},
expected: 'https://wikiwho.example.com/en/whocolor/v1.0.0-beta/Test%20Works%3Fuser-ip%3D0.0.0.0%26/123/'
}
];

Expand Down

0 comments on commit 677269a

Please sign in to comment.