Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

afd not transcluded properly if title of page contains "$1" #1993

Open
41922 opened this issue Aug 22, 2024 · 5 comments
Open

afd not transcluded properly if title of page contains "$1" #1993

41922 opened this issue Aug 22, 2024 · 5 comments

Comments

@41922
Copy link

41922 commented Aug 22, 2024

or so i think?
https://en.wikipedia.org/w/index.php?title=Wikipedia:Articles_for_deletion/Log/2024_August_22&diff=prev&oldid=1241631405

@NovemLinguae
Copy link
Member

There's probably an a.replace( b, c ) somewhere. $&, $1, $2, $3, $4, etc. are special characters in the "c" field and should be escaped. The fix here is probably to run some kind of escape algorithm on "c".

@nardog
Copy link
Contributor

nardog commented Aug 22, 2024

You can use mw.util.escapeRegExp(). Nvm, the replace not the search string.

@NovemLinguae
Copy link
Member

NovemLinguae commented Aug 22, 2024

Stack Overflow says the proper way to escape this is to add a dollar sign in front of every special string. So $&, $1, $2, $3, $4 -> $$&, $$1, $$2, $$3, $$4

https://stackoverflow.com/a/28102904/3480193

Someone's probably written a bulletproof function for this somewhere. I imagine it'd be something like...

function escapeSecondParameterOfRegexReplace( secondParameter ) {
    return secondParameter.replace( /(\$(?:\d+|&))/g, '$$$1' );
}

https://regex101.com/r/7yjT4v/1

Todo:

  • change escapeSecondParameterOfRegexReplace to escapeSecondParameterOfReplace if $1 works for non regex, too
  • does .replace freak out for any other special strings, such as $ by itself, or $$? if so those will need escaping too
  • does the simpler .replace( '$', '$$' ) work? this is kind of suggested by the Stack Overflow answer above

edit: here's some more special ones...

https://es5.github.io/#x15.5.4.11

image

@NovemLinguae
Copy link
Member

Ah here we go.

https://stackoverflow.com/a/6969486/3480193

function escapeReplacement(string) {
    return string.replace(/\$/g, '$$$$');
}

@siddharthvp
Copy link
Member

We have that function in morebits: Morebits.string.safeReplace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants