Skip to content

Commit

Permalink
regexp: uses unmatched as null (BC break)
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 21, 2025
1 parent 1d845e8 commit e2749bf
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 56 deletions.
2 changes: 1 addition & 1 deletion src/Texy/Modules/BlockQuoteModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function pattern(Texy\BlockParser $parser, array $matches): Texy\HtmlElem
}
$content .= $mContent . "\n";

if (!$parser->next("~^>(?: | ([\\ \\t]{1,$spaces} | :) (.*))()$~mA", $matches)) {
if (!$parser->next("~^>(?: | ([\\ \\t]{1,$spaces} | :) (.*))$~mA", $matches)) {
break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Texy/Modules/FigureModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function __construct(Texy\Texy $texy)
\ ++ \*\*\* \ ++ # separator
(.{0,2000}) # figure content
' . Patterns::MODIFIER_H . '?
()$~mU',
$~mU',
'figure',
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Texy/Modules/HeadingModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function __construct(Texy\Texy $texy)
( \#{2,}+ | ={2,}+ ) # opening characters
(.+) # heading text
' . Texy\Patterns::MODIFIER_H . '?
()$~mU',
$~mU',
'heading/surrounded',
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Texy/Modules/HorizLineModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(Texy\Texy $texy)
( \*{3,}+ | -{3,}+ ) # three or more * or -
[\ \t]* # optional spaces
' . Texy\Patterns::MODIFIER . '?
()$~mU',
$~mU',
'horizline',
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Texy/Modules/HtmlModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ private function parseAttributes(string $attrs): array
[^'"\s]+ # unquoted value
)
)?
()~is
~is
X,
);

Expand Down
2 changes: 1 addition & 1 deletion src/Texy/Modules/HtmlOutputModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private function postProcess(Texy\Texy $texy, string &$s): void
'~
( [^<]*+ )
< (?: (!--.*--) | (/?) ([a-z][a-z0-9._:-]*) (|[ \n].*) \s* (/?) ) >
()~Uis',
~Uis',
$this->cb(...),
);

Expand Down
8 changes: 4 additions & 4 deletions src/Texy/Modules/ImageModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function __construct(Texy\Texy $texy)
(?:
:(' . Patterns::LINK_URL . ' | : ) # link or just colon
)??
()~U',
~U',
'image',
);

Expand All @@ -88,7 +88,7 @@ private function beforeParse(Texy\Texy $texy, &$text): void
[\ \t]*
' . Patterns::MODIFIER . '?
\s*
()$~mU',
$~mU',
$this->patternReferenceDef(...),
);
}
Expand Down Expand Up @@ -167,7 +167,7 @@ public function getReference(string $name): ?Image
/**
* Parses image's syntax. Input: small.jpg 80x13 || linked.jpg
*/
public function factoryImage(string $content, string $mod, bool $tryRef = true): Image
public function factoryImage(string $content, ?string $mod, bool $tryRef = true): Image
{
$image = $tryRef ? $this->getReference(trim($content)) : null;

Expand All @@ -178,7 +178,7 @@ public function factoryImage(string $content, string $mod, bool $tryRef = true):

// dimensions
$matches = null;
if ($matches = Texy\Regexp::match($content[0], '~^(.*)\ (\d+|\?)\ *(X|x)\ *(\d+|\?)\ *()$~U')) {
if ($matches = Texy\Regexp::match($content[0], '~^(.*)\ (\d+|\?)\ *(X|x)\ *(\d+|\?)\ *$~U')) {
$image->URL = trim($matches[1]);
$image->asMax = $matches[3] === 'X';
$image->width = $matches[2] === '?' ? null : (int) $matches[2];
Expand Down
16 changes: 8 additions & 8 deletions src/Texy/Modules/LinkModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private function beforeParse(Texy\Texy $texy, &$text): void
( [\ \t] .{1,1000} )? # optional description
' . Patterns::MODIFIER . '?
\s*
()$~mU',
$~mU',
$this->patternReferenceDef(...),
);
}
Expand All @@ -138,7 +138,7 @@ private function patternReferenceDef(array $matches): string
// [4] => .(title)[class]{style}

$link = new Link($mLink);
$link->label = trim($mLabel);
$link->label = trim($mLabel ?? '');
$link->modifier->setProperties($mMod);
$this->checkLink($link);
$this->addReference($mRef, $link);
Expand Down Expand Up @@ -397,29 +397,29 @@ private function textualUrl(Link $link): string
(?P<path> (?: / | ^ ) (?! / ) [^?#]* )?
(?: \? (?P<query> [^#]* ) )?
(?: \# (?P<fragment> .* ) )?
()$
$
~'))) {
return $link->raw;
}

$res = '';
if ($parts['scheme'] !== '' && $parts['scheme'] !== 'none') {
if ($parts['scheme'] !== null && $parts['scheme'] !== 'none') {
$res .= $parts['scheme'] . '://';
}

if ($parts['host'] !== '') {
if ($parts['host'] !== null) {
$res .= $parts['host'];
}

if ($parts['path'] !== '') {
if ($parts['path'] !== null) {
$res .= (iconv_strlen($parts['path'], 'UTF-8') > 16 ? ("/\u{2026}" . iconv_substr($parts['path'], -12, 12, 'UTF-8')) : $parts['path']);
}

if ($parts['query'] !== '') {
if ($parts['query'] > '') {
$res .= iconv_strlen($parts['query'], 'UTF-8') > 4
? "?\u{2026}"
: ('?' . $parts['query']);
} elseif ($parts['fragment'] !== '') {
} elseif ($parts['fragment'] > '') {
$res .= iconv_strlen($parts['fragment'], 'UTF-8') > 4
? "#\u{2026}"
: ('#' . $parts['fragment']);
Expand Down
6 changes: 3 additions & 3 deletions src/Texy/Modules/ListModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public function patternDefList(BlockParser $parser, array $matches): HtmlElement
( \S .* ) # term content
\: [\ \t]* # colon separator
' . Patterns::MODIFIER_H . '?
()$~mUA';
$~mUA';

while (true) {
if ($elItem = $this->patternItem($parser, $bullet, true, 'dd')) {
Expand Down Expand Up @@ -225,7 +225,7 @@ private function patternItem(BlockParser $parser, string $bullet, bool $indented
[ \\t]*
( \\S .* )? # content
" . Patterns::MODIFIER_H . '?
()$~mAU';
$~mAU';

// first line with bullet
$matches = null;
Expand All @@ -250,7 +250,7 @@ private function patternItem(BlockParser $parser, string $bullet, bool $indented
' . Regexp::quote($mIndent) . '
([\ \t]{1,' . $spaces . '})
(.*)
()$~Am', $matches)) {
$~Am', $matches)) {
[, $mBlank, $mSpaces, $mContent] = $matches;
// [1] => blank line?
// [2] => spaces
Expand Down
47 changes: 23 additions & 24 deletions src/Texy/Modules/PhraseModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function __construct(Texy\Texy $texy)
// UNIVERSAL
$texy->registerLinePattern(
array($this, 'patternPhrase'),
'~((?>([*+/^_"\~`-])+?))(?!\s)(.*(?!\2).)'.Texy\Patterns::MODIFIER.'?(?<!\s)\1(?!\2)(?::('.Texy\Patterns::LINK_URL.'))??()~Us',
'~((?>([*+/^_"\~`-])+?))(?!\s)(.*(?!\2).)'.Texy\Patterns::MODIFIER.'?(?<!\s)\1(?!\2)(?::('.Texy\Patterns::LINK_URL.'))??~Us',
'phrase/strong'
);
*/
Expand All @@ -71,7 +71,7 @@ public function __construct(Texy\Texy $texy)
\*\*\*
(?! \* ) # not followed by *
(?: :(' . Patterns::LINK_URL . ') )?? # optional link
()~Us',
~Us',
'phrase/strong+em',
);

Expand All @@ -88,7 +88,7 @@ public function __construct(Texy\Texy $texy)
\*\*
(?! \* ) # not followed by *
(?: :(' . Patterns::LINK_URL . ') )?? # optional link
()~Us',
~Us',
'phrase/strong',
);

Expand All @@ -105,7 +105,7 @@ public function __construct(Texy\Texy $texy)
\/\/
(?! \/ ) # not followed by /
(?: :(' . Patterns::LINK_URL . ') )?? # optional link
()~Us',
~Us',
'phrase/em',
);

Expand All @@ -122,7 +122,7 @@ public function __construct(Texy\Texy $texy)
\*
(?! \* ) # not followed by *
(?: :(' . Patterns::LINK_URL . ') )?? # optional link
()~Us',
~Us',
'phrase/em-alt',
);

Expand All @@ -139,7 +139,7 @@ public function __construct(Texy\Texy $texy)
\*
(?! [^\s.,;:<>()"?!\'-] ) # must be followed by these chars
(?: :(' . Patterns::LINK_URL . ') )?? # optional link
()~Us',
~Us',
'phrase/em-alt2',
);

Expand All @@ -155,7 +155,7 @@ public function __construct(Texy\Texy $texy)
(?<! [\s+] ) # not preceded by space or +
\+\+
(?! \+ ) # not followed by +
()~U',
~U',
'phrase/ins',
);

Expand All @@ -171,7 +171,7 @@ public function __construct(Texy\Texy $texy)
(?<! [\s<-] ) # not preceded by space, < or -
\-\-
(?! [>-] ) # not followed by > or -
()~U',
~U',
'phrase/del',
);

Expand All @@ -187,7 +187,7 @@ public function __construct(Texy\Texy $texy)
(?<! [\s^] ) # not preceded by space or ^
\^\^
(?! \^ ) # not followed by ^
()~U',
~U',
'phrase/sup',
);

Expand Down Expand Up @@ -215,7 +215,7 @@ public function __construct(Texy\Texy $texy)
(?<! [\s_] ) # not preceded by space or _
\_\_
(?! \_ ) # not followed by _
()~U',
~U',
'phrase/sub',
);

Expand Down Expand Up @@ -244,7 +244,7 @@ public function __construct(Texy\Texy $texy)
\"
(?! \" ) # not followed by "
(?: :(' . Patterns::LINK_URL . ') )?? # optional link
()~U',
~U',
'phrase/span',
);

Expand All @@ -261,7 +261,7 @@ public function __construct(Texy\Texy $texy)
\~
(?! \~ )
(?: :(' . Patterns::LINK_URL . ') )?? # optional link
()~U',
~U',
'phrase/span-alt',
);

Expand All @@ -278,7 +278,7 @@ public function __construct(Texy\Texy $texy)
\<\<
(?! \< ) # not followed by
(?: :(' . Patterns::LINK_URL . ') )?? # optional link
()~U',
~U',
'phrase/quote',
);

Expand All @@ -297,7 +297,7 @@ public function __construct(Texy\Texy $texy)
\(\(
( .+ ) # explanation
\)\)
()~U',
~U',
'phrase/acronym',
);

Expand Down Expand Up @@ -326,7 +326,7 @@ public function __construct(Texy\Texy $texy)
(?<! [\s\'] ) # not preceded by space or quote
\'\'
(?! \' ) # not followed by quote
()~U',
~U',
'phrase/notexy',
);

Expand All @@ -340,7 +340,7 @@ public function __construct(Texy\Texy $texy)
(?<! \s ) # not preceded by space
\`
(?: : (' . Patterns::LINK_URL . ') )?? # optional link
()~U',
~U',
'phrase/code',
);

Expand All @@ -352,7 +352,7 @@ public function __construct(Texy\Texy $texy)
() # empty group
(?= :\[ ) # followed by :[
(?: : (' . Patterns::LINK_URL . ') ) # link
()~U',
~U',
'phrase/quicklink',
);

Expand All @@ -370,7 +370,7 @@ public function __construct(Texy\Texy $texy)
(?<! \s ) # not preceded by space
\]
(?! \] ) # not followed by ]
()~U',
~U',
'phrase/wikilink',
);

Expand All @@ -388,7 +388,7 @@ public function __construct(Texy\Texy $texy)
\(
( (?: [^' . Patterns::MARK . '\r )]++ | [ ] )+ ) # link
\)
()~U',
~U',
'phrase/markdown',
);

Expand All @@ -411,11 +411,10 @@ public function __construct(Texy\Texy $texy)
*/
public function patternPhrase(LineParser $parser, array $matches, string $phrase): Texy\HtmlElement|string|null
{
[, $mContent, $mMod, $mLink] = $matches;
// [1] => **
// [2] => ...
// [3] => .(title)[class]{style}
// [4] => LINK
[, $mContent, $mMod, $mLink] = $matches + [3 => null];
// [1] => ...
// [2] => .(title)[class]{style}
// [3] => LINK

if ($phrase === 'phrase/wikilink') {
[$mLink, $mMod] = [$mMod, $mLink];
Expand Down
2 changes: 1 addition & 1 deletion src/Texy/Modules/ScriptModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(Texy\Texy $texy)
[}] # or single }
)+)
\}\}
()~U',
~U',
'script',
);
}
Expand Down
Loading

0 comments on commit e2749bf

Please sign in to comment.