Last modified: 2011-10-25 14:30:48 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T33499, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 31499 - WikiEditor articlePathRegex is invalid for internal link detection in 1.17.0
WikiEditor articlePathRegex is invalid for internal link detection in 1.17.0
Status: RESOLVED FIXED
Product: MediaWiki extensions
Classification: Unclassified
WikiEditor (Other open bugs)
unspecified
All All
: Unprioritized normal (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-10-07 17:04 UTC by Dan Barrett
Modified: 2011-10-25 14:30 UTC (History)
2 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments
Patch for regular expression problem (933 bytes, patch)
2011-10-07 17:09 UTC, Dan Barrett
Details

Description Dan Barrett 2011-10-07 17:04:32 UTC
The code in WikiEditor for detecting "external internal" links like http://en.wikipedia.org/wiki/Foobar is broken due to an incorrect regular expression.  The following code appears in ext.wikiEditor.dialogs.js in 1.17.0 (and in jquery.wikiEditor.dialogs.config.js in later MW versions):

$(this).data( 'articlePathRegex', new RegExp(
  '^' + $.escapeRE( mw.config.get( 'wgServer' ) + mw.config.get( 'wgArticlePath' ) )
  .replace( /\\\$1/g, '(.*)' ) + '$'
) );

The problem is that $.escapeRE converts this string:

http://mywiki.com/wiki/$1

into:

"^http\:\/\/mywiki\.com\/wiki\/\$\1$"

The problem is the slash before the "1". As a result, the replacement:

.replace( /\\\$1/g, '(.*)' ) + '$'

fails to match, so the $1 does not get replaced by "(.*)".

A quick fix would be to change the replace() call to:

.replace( /\\\$\\1/g, '(.*)' ) + '$'

but honestly, I don't understand why $.escapeRE turns "$1" into "\$\1".  I think it should be turning it into "\$1".  Maybe $1 has special meaning to $.escapeRE, as a back-reference or something?
Comment 1 Dan Barrett 2011-10-07 17:09:45 UTC
Created attachment 9183 [details]
Patch for regular expression problem
Comment 2 Roan Kattouw 2011-10-25 13:54:26 UTC
$.escapeRE() should be fixed here. I'll investigate.
Comment 3 Roan Kattouw 2011-10-25 13:58:19 UTC
>>> $.escapeRE("http://mywiki.com/wiki/$1")
"http://mywiki\.com/wiki/\$1"

Is what I get in trunk (where $.escapeRE() has been moved to trunk/phase3/resources/jquery/jquery.mwExtension.js). Which version did you get your results on?
Comment 4 Dan Barrett 2011-10-25 14:19:14 UTC
I am using 1.17.0. Firebug gives the buggy results:

>>> $.escapeRE("http://mywiki.com/wiki/$1");
"http\:\/\/mywiki\.com\/wiki\/\$\1"

When I hit English Wikipedia and check against 1.18.0wmf, I get correct results:

>>> $.escapeRE("http://mywiki.com/wiki/$1");
"http://mywiki\.com/wiki/\$1"

There might still be a problem on English Wikipedia however, because of the following use case:

0. Visit en.wikipedia.org and edit any page.
1. Click the Link button in the editor.
2. Enter http://en.wikipedia.org/wiki/Dog as the link and click "Insert link".
3. You *should* get a pop-up dialog that says "The URL you specified looks like it was intended as a link to another wiki page. Do you want to make it an internal link?" (message MediaWiki:Wikieditor-toolbar-tool-link-lookslikeinternal), however no dialog appears.
Comment 5 Roan Kattouw 2011-10-25 14:21:04 UTC
(In reply to comment #4)
> I am using 1.17.0. Firebug gives the buggy results:
> 
> >>> $.escapeRE("http://mywiki.com/wiki/$1");
> "http\:\/\/mywiki\.com\/wiki\/\$\1"
> 
> When I hit English Wikipedia and check against 1.18.0wmf, I get correct
> results:
> 
> >>> $.escapeRE("http://mywiki.com/wiki/$1");
> "http://mywiki\.com/wiki/\$1"
> 
> There might still be a problem on English Wikipedia however, because of the
> following use case:
> 
> 0. Visit en.wikipedia.org and edit any page.
> 1. Click the Link button in the editor.
> 2. Enter http://en.wikipedia.org/wiki/Dog as the link and click "Insert link".
> 3. You *should* get a pop-up dialog that says "The URL you specified looks like
> it was intended as a link to another wiki page. Do you want to make it an
> internal link?" (message
> MediaWiki:Wikieditor-toolbar-tool-link-lookslikeinternal), however no dialog
> appears.
Hah, that's probably because wgServer is protocol-relative now:

>>> mw.config.get('wgServer')
"//en.wikipedia.org"
Comment 6 Roan Kattouw 2011-10-25 14:30:48 UTC
Fixed in r100699.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links