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

special characters in prompts need to be escaped before being used in a regex. #98

Closed
jimhester opened this Issue Sep 15, 2017 · 0 comments

Comments

Projects
None yet
1 participant
@jimhester
Member

jimhester commented Sep 15, 2017

I just changed my prompt to be a blue > with

getOption("prompt")
#> [1] "\033[34m> \033[39m"

Which now gives the following output when you try to use reprex

reprex::reprex(input = "x <- 1\n")
Error in grepl(regex, x) :
  invalid regular expression '^> ', reason 'Missing ']''

This is because

reprex/R/ensure.R

Lines 25 to 26 in 04fcbbc

regex <- paste0("^", prompt)
prompts <- grepl(regex, x)

Does not escape the prompt for special regex characters before passing it to grepl().

Will have a PR to fix this shortly.

jimhester added a commit to jimhester/reprex that referenced this issue Sep 15, 2017

Escape prompts when used in regexes
Doing so ensures prompts which contain special characters in regular
expressions do not cause errors or unintended regular expressions.

Fixes tidyverse#98

@jennybc jennybc closed this in #99 Sep 15, 2017

jennybc added a commit that referenced this issue Sep 15, 2017

Escape prompts when used in regexes (#99)
Doing so ensures prompts which contain special characters in regular
expressions do not cause errors or unintended regular expressions.

Fixes #98
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment