Skip to content

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

@jimhester

Description

@jimhester

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.

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