Fix undefined behaviour for pages with numbers as title (e.g 7) #52
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When requesting the page "23", it is expected to receive this page: https://en.wikipedia.org/wiki/23
Expected behavior:
wiki.page("23") -> https://en.wikipedia.org/wiki/23
wiki.page(23) -> https://en.wikipedia.org/wiki/Assistive_technology
Actual behavior:
wiki.page("23") -> https://en.wikipedia.org/wiki/Assistive_technology
(which has ID 23)wiki.page(23) -> https://en.wikipedia.org/wiki/Assistive_technology
So there is no way to get the page for the number 23 or for example years like 1939, sine they will be treated as IDs.
It is checked whether an ID or a Title is given by
isNaN(title)
in utils.ts, the String "7" will be handled like a page ID.Instead check the actual type of what the function receives:
return typeof title === 'string' || title instanceof String;
New behavior:
wiki.page("23") -> https://en.wikipedia.org/wiki/23
wiki.page(23) -> https://en.wikipedia.org/wiki/Assistive_technology
-> Supply a number, get a page by ID, supply a string, get the page by title