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

escape hyphen for compatibility with PCRE 2 (for R 4.0.0) #502

Merged
merged 3 commits into from Jul 10, 2020

Conversation

jan-glx
Copy link
Contributor

@jan-glx jan-glx commented May 19, 2020

PCRE 2 is the new default for R 4.0.0:

PCRE2 reports errors for some regular expressions that were accepted by PCRE1. A hyphen now has to be escaped in a character class to be interpreted as a literal (unless first or last in the class definition). \R, \B and \X are no longer allowed in character classes (PCRE1 treated these as literals).

without this fix installation of packages with submodules will fail. For example, when installing emo:

> devtools::install_github("hadley/emo")
Downloading GitHub repo hadley/emo@master
Error: Failed to install 'emo' from GitHub:
  invalid regular expression '^[[:space:]]*(?<name>[[:alpha:]][[:alnum:]-]*)[[:space:]]*=[[:space:]]*(?<value>.*)[[:space:]]*$'
In addition: Warning message:
In regexpr(pattern, text, perl = perl, ...) :
  PCRE pattern compilation error
	'invalid range in character class'
	at '-]*)[[:space:]]*=[[:space:]]*(?<value>.*)[[:space:]]*$'

Demonstration of the fix:

> .gitmodules_example <- c("[submodule \"data-raw/gemoji\"]","\tpath = data-raw/gemoji","\turl = https://github.com/github/gemoji.git", "[submodule \"data-raw/emojilib\"]")
> regexpr("^[[:space:]]*(?<name>[[:alpha:]][[:alnum:]-]*)[[:space:]]*=[[:space:]]*(?<value>.*)[[:space:]]*$", .gitmodules_example, perl =TRUE)
Error in regexpr("^[[:space:]]*(?<name>[[:alpha:]][[:alnum:]-]*)[[:space:]]*=[[:space:]]*(?<value>.*)[[:space:]]*$",  : 
  invalid regular expression '^[[:space:]]*(?<name>[[:alpha:]][[:alnum:]-]*)[[:space:]]*=[[:space:]]*(?<value>.*)[[:space:]]*$'
In addition: Warning message:
In regexpr("^[[:space:]]*(?<name>[[:alpha:]][[:alnum:]-]*)[[:space:]]*=[[:space:]]*(?<value>.*)[[:space:]]*$",  :
  PCRE pattern compilation error
	'invalid range in character class'
	at '-]*)[[:space:]]*=[[:space:]]*(?<value>.*)[[:space:]]*$'
> regexpr("^[[:space:]]*(?<name>[[:alpha:]][[:alnum:]\\-]*)[[:space:]]*=[[:space:]]*(?<value>.*)[[:space:]]*$", .gitmodules_example, perl =TRUE)
[1] -1  1  1 -1
attr(,"match.length")
[1] -1 23 43 -1
attr(,"index.type")
[1] "chars"
attr(,"useBytes")
[1] TRUE
attr(,"capture.start")
     name value
[1,]   -1    -1
[2,]    2     9
[3,]    2     8
[4,]   -1    -1
attr(,"capture.length")
     name value
[1,]   -1    -1
[2,]    4    15
[3,]    3    36
[4,]   -1    -1
attr(,"capture.names")
[1] "name"  "value"

@jan-glx
Copy link
Contributor Author

jan-glx commented May 19, 2020

Patch was not tested by me.

@jimhester
Copy link
Member

jimhester commented Jul 10, 2020

Thanks!

Hey! Thanks!

@jimhester jimhester merged commit ee36655 into r-lib:master Jul 10, 2020
0 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants