Skip to content

Commit

Permalink
Fix trimming spaces between title and fragment
Browse files Browse the repository at this point in the history
 * A string is not a regexp.

 * Also, other somewhat related cleanup.
  • Loading branch information
arlolra committed Jun 22, 2017
1 parent 408593b commit 81d85ed
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/index.js
Expand Up @@ -361,7 +361,7 @@ Title.newFromText = function(title, siteInfo, defaultNs) {
// Initial colon indicates main namespace rather than specified default
// but should not create invalid {ns,title} pairs such as {0,Project:Foo}
if (title !== '' && title[0] === ':') {
title = title.substr(1).replace(/(?:^_+)|(?:_+$)/g, '');
title = title.substr(1).replace(/^_+/, '');

This comment has been minimized.

Copy link
@subbuss

subbuss Jun 22, 2017

Collaborator

So, is a title like ":foo " trimmed before it gets here? since you've removed the second half of the regexp. Is that covered by tests?

}

_checkEmptyTitle(title);
Expand All @@ -377,10 +377,10 @@ Title.newFromText = function(title, siteInfo, defaultNs) {
var fragmentIndex = result.title.indexOf('#');
if (fragmentIndex >= 0) {
var fragment = result.title.substr(fragmentIndex);
result.fragment = fragment.substr(1).replace(/ /g, '_');
result.fragment = fragment.substr(1);
result.title = result.title
.substring(0, result.title.length - fragment.length)
.replace('/_*$/', '');
.replace(/_+$/, '');
}

_checkLegalTitleCharacters(result.title, siteInfo);
Expand Down
3 changes: 2 additions & 1 deletion test/index.js
Expand Up @@ -157,6 +157,7 @@ function doTest(formatversion) {
[ 'en.wikipedia.org', 'Talk: foo', 'Talk:Foo'],
[ 'en.wikipedia.org', 'int:eger', 'Int:eger'],
[ 'en.wikipedia.org', 'WP:eger', 'Wikipedia:Eger'],
[ 'en.wikipedia.org', 'X-Men (film series) #Gambit', 'X-Men_(film_series)' ],
// Special handling for `i` first character
[ 'tr.wikipedia.org', 'iTestTest', 'İTestTest'],
[ 'az.wikipedia.org', 'iTestTest', 'İTestTest'],
Expand Down Expand Up @@ -272,7 +273,7 @@ function doTest(formatversion) {
.then(function(res) {
assert.deepEqual(res.getFragment(), 'some_fragment');
});
})
});
});

describe('Defaults', function() {
Expand Down

0 comments on commit 81d85ed

Please sign in to comment.