Skip to content

Commit 3e4d902

Browse files
committed
Use native PCRE unicode properties to detect capital letters
1 parent d84b99b commit 3e4d902

File tree

1 file changed

+8
-35
lines changed

1 file changed

+8
-35
lines changed

src/fixes/node-fixes/class-style-caps-fix.php

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -33,60 +33,33 @@
3333
/**
3434
* Wraps words of all caps (may include numbers) in <span class="caps"> if enabled.
3535
*
36-
* Call before style_numbers().Only call if you are certain that no html tags have been
37-
* injected containing capital letters.
36+
* Call before style_numbers(). Only call if you are certain that no html tags have
37+
* been injected containing capital letters.
3838
*
3939
* @author Peter Putzer <github@mundschenk.at>
4040
*
4141
* @since 5.0.0
4242
*/
4343
class Style_Caps_Fix extends Simple_Style_Fix {
44-
/*
45-
// \p{Lu} equals upper case letters and should match non english characters; since PHP 4.4.0 and 5.1.0
46-
// for more info, see http://www.regextester.com/pregsyntax.html#regexp.reference.unicode
47-
$this->components[ Settings::STYLE_CAPS ] = '
48-
(?<![\w\-_'.U::ZERO_WIDTH_SPACE.U::SOFT_HYPHEN.'])
49-
# negative lookbehind assertion
50-
(
51-
(?: # CASE 1: " 9A "
52-
[0-9]+ # starts with at least one number
53-
\p{Lu} # must contain at least one capital letter
54-
(?:\p{Lu}|[0-9]|\-|_|'.U::ZERO_WIDTH_SPACE.'|'.U::SOFT_HYPHEN.')*
55-
# may be followed by any number of numbers capital letters, hyphens, underscores, zero width spaces, or soft hyphens
56-
)
57-
|
58-
(?: # CASE 2: " A9 "
59-
\p{Lu} # starts with capital letter
60-
(?:\p{Lu}|[0-9]) # must be followed a number or capital letter
61-
(?:\p{Lu}|[0-9]|\-|_|'.U::ZERO_WIDTH_SPACE.'|'.U::SOFT_HYPHEN.')*
62-
# may be followed by any number of numbers capital letters, hyphens, underscores, zero width spaces, or soft hyphens
6344

64-
)
65-
)
66-
(?![\w\-_'.U::ZERO_WIDTH_SPACE.U::SOFT_HYPHEN.'])
67-
# negative lookahead assertion
68-
'; // required modifiers: x (multiline pattern) u (utf8)
69-
*/
70-
71-
// Servers with PCRE compiled without "--enable-unicode-properties" fail at \p{Lu} by returning an empty string (this leaving the screen void of text
72-
// thus are testing this alternative.
45+
// PCRE needs to be compiled with "--enable-unicode-properties", but we already depend on that elsehwere.
7346
const REGEX = '/
7447
(?<![\w' . self::COMBINING_MARKS . ']) # negative lookbehind assertion
7548
(
7649
(?: # CASE 1: " 9A "
7750
[0-9]+ # starts with at least one number
7851
(?:[' . self::COMBINING_MARKS . '])*
7952
# may contain hyphens, underscores, zero width spaces, or soft hyphens,
80-
[A-ZÀ-ÖØ-Ý] # but must contain at least one capital letter
81-
(?:[A-ZÀ-ÖØ-Ý]|[0-9]|[' . self::COMBINING_MARKS . '])*
53+
\p{Lu} # but must contain at least one capital letter
54+
(?:\p{Lu}|[0-9]|[' . self::COMBINING_MARKS . '])*
8255
# may be followed by any number of numbers capital letters, hyphens,
8356
# underscores, zero width spaces, or soft hyphens
8457
)
8558
|
8659
(?: # CASE 2: " A9 "
87-
[A-ZÀ-ÖØ-Ý] # starts with capital letter
88-
(?:[A-ZÀ-ÖØ-Ý]|[0-9]) # must be followed a number or capital letter
89-
(?:[A-ZÀ-ÖØ-Ý]|[0-9]|[' . self::COMBINING_MARKS . '])*
60+
\p{Lu} # starts with capital letter
61+
(?:\p{Lu}|[0-9]) # must be followed a number or capital letter
62+
(?:\p{Lu}|[0-9]|[' . self::COMBINING_MARKS . '])*
9063
# may be followed by any number of numbers capital letters, hyphens,
9164
# underscores, zero width spaces, or soft hyphens
9265
)

0 commit comments

Comments
 (0)