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

Missing utf_mode handling for PCRE2 #610

Open
stephane-chazelas opened this issue Mar 2, 2025 · 1 comment
Open

Missing utf_mode handling for PCRE2 #610

stephane-chazelas opened this issue Mar 2, 2025 · 1 comment

Comments

@stephane-chazelas
Copy link

PCRE regexp support had:

        pcre *comp = pcre_compile(pattern,
                        ((utf_mode) ? PCRE_UTF8 | PCRE_NO_UTF8_CHECK : 0) |

Meaning regexps would work properly at matching UTF-8 encoded text in UTF-8 locales, but with PCRE2 (with less built with --with-regex=pcre2)

echo Stéphane | LESSCHARSET=utf-8 LC_ALL=en_GB.UTF-8 ./less +/St.ph

Reports Pattern not found, and one needs: (*UTF)St.p instead of just St.p as the regexp when matching UTF-8 encoded text.

According to NEWS, PCRE2 support was added at the same time as those PCRE_UTF8 flags were added to PCRE, which seems odd to me. Why not add it for both PCRE and PCRE2 at the time?

It seems to me the fix should just be a matter of:

diff --git a/pattern.c b/pattern.c
index 0c651bd..6534156 100644
--- a/pattern.c
+++ b/pattern.c
@@ -81,6 +81,7 @@ static int compile_pattern2(constant char *pattern, int search_type, PATTERN_TYP
 	PCRE2_SIZE erroffset;
 	PARG parg;
 	pcre2_code *comp = pcre2_compile((PCRE2_SPTR)pattern, strlen(pattern),
+			((utf_mode) ? PCRE2_UTF | PCRE2_NO_UTF_CHECK : 0) |
 			(is_caseless ? PCRE2_CASELESS : 0),
 			&errcode, &erroffset, NULL);
 	if (comp == NULL)

To do the same like with PCRE.

gwsw added a commit that referenced this issue Mar 3, 2025
Need to pass the PCRE2_UTF flag to pcre2_compile when
we are using the UTF-8 charset.

Related to #610.
@gwsw
Copy link
Owner

gwsw commented Mar 3, 2025

Fixed in 5f60178.

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

No branches or pull requests

2 participants