System - SEF incorrectly prepends / to query-only relative URLs

In a clean Joomla 5/6 installation with System - SEF enabled, an article containing <a href="/?start=3"> is rendered with the link changed to <a href="/?start=3">.

Query-only relative URLs are valid URLs and should preserve the current document path.

The problem is caused by the URL-rewriting regex in plugins/system/sef/src/Extension/Sef.php, which does not exclude ? from its relative URL detection.

Adding \? to the negative lookahead fixes the problem. (Line 305)

Also see [nx-finder-fix (nxfinderfix) plugin]


File:
plugins/system/sef/src/Extension/Sef.php

Original: (Line 305)
$regex = '#\s' . $attribute . '"(?!/|' . $protocols . '|\#|\')([^"]*)"#m';

Modified:
$regex = '#\s' . $attribute . '"(?!/|' . $protocols . '|\#|\?|\')([^"]*)"#m';

Reason:
System - SEF incorrectly prepends the site base path to query-only relative URLs such as ?start=3.

PAGE 0