Skip to content
This repository was archived by the owner on Apr 16, 2026. It is now read-only.
This repository was archived by the owner on Apr 16, 2026. It is now read-only.

Searching for some strings containing backslash finds nothing #5428

Closed

Description

Tested on http://codemirror.net/demo/search.html
Firefox Nightly, Chromium 66

STR:

  • copy this into textbox on demo page
padding
www\tfoo
wwwww	<- tab
www\/?foo
test for t
  • try searching for www\t or www\/? using CodeMirror search feature
  • nothing is found
  • searching for \n finds new lines
  • searching for \t does not find \t or tab, but finds t

parseString in search.js replaces \n and \r to LF and CR, but strips backslashes from other looks-alike escape sequences in query string.

Real case is I cannot find
/(watchcartoononline|9anime|memecenter|kimcartoon|animeflv).*[a-zA-Z0-9&%=\/?]{40,}/$script,~third-party

in content of EasyList in uBlock Origin setting

...
@@||youtube.com/iframe_api$third-party
@@||youtube.com/player_api$third-party
! 
/(watchcartoononline|9anime|memecenter|kimcartoon|animeflv).*[a-zA-Z0-9&%=\/?]{40,}/$script,~third-party
/(watchcartoononline|9anime|memecenter|kimcartoon|animeflv).*\/.*[(&|=|%|\/|?)]{50,}/$image,script
@@||9anime.is/assets/min/frontend/all.js$script
@@||9anime.is/assets/player/jwplayer-7.12.3/jwplayer.js$script
...

Filters may be complicated, and may be not easy to find all backslashes and escape them.

Activity

  1. gorhill commented on Jul 7, 2019

    @gorhill
    Contributor

    The fix is trivial in practice, which is to slightly rewrite parseString in https://github.com/codemirror/CodeMirror/blob/c9892c85b02e448370798edd374d6cbc9bb41272/addon/search/search.js#L80-L86 to:

    function parseString(string) {
        return string.replace(/\\([nrt\\])/g, function(match, ch) {
            if (ch == "n") return "\n"
            if (ch == "r") return "\r"
            if (ch == "t") return "\t"
            if (ch == "\\") return "\\"
            return match
        })
    }
    

    Essentially, eat the backslash only for specific characters, and use backslash literally for all other characters.

    However I am not sure why this was implemented the way it is, so I am unsure whether such change would be accepted.

  2. marijnh commented on Jul 7, 2019

    @marijnh
    Member

    However I am not sure why this was implemented the way it is

    It is following the way JavaScript/C strings work (with less supported escapes) where unrecognized escapes just result in the escaped character (i.e. "\i" == "i").

    There's no well-defined user expectation here — the current behavior was added because people wanted to be able to use \n, but disappoints the expectation of being able to insert backslashes the simple way. Your patch would probably cause this to be less surprising, so if you want to submit a pull request that'd be great.

  3. added a commit that references this issue on Jan 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions