-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Fix SEF plugin breaking HTML while trying to make inline background url paths absolute #11266
Conversation
Works for me now. Thx |
please visit and click "Test this" and the select "Tested successfuly" to mark a successful test |
I have tested this item ✅ successfully on ff76cd8 This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/11266. |
I have tested this item ✅ successfully on ff76cd8 This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/11266. |
See results: This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/11266. |
Rtc This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/11266. |
No longer RTC, it needs retesting, since i added handling of:
to fix issue: #7267 |
@@ -153,8 +153,9 @@ public function onAfterRender() | |||
// Replace all unknown protocols in CSS background image. | |||
if (strpos($buffer, 'style=') !== false) | |||
{ | |||
$regex = '#style=\s*[\'\"](.*):\s*url\s*\([\'\"]?(?!/|' . $protocols . '|\#)([^\)\'\"]+)[\'\"]?\)#m'; | |||
$buffer = preg_replace($regex, 'style="$1: url(\'' . $base . '$2$3\')', $buffer); | |||
$regex_url = '\s*url\s*\(([\'\"]|\&\#0?3[4|9];)?(?!/|\&\#0?3[4|9];|' . $protocols . '|\#)([^\)\'\"]+)([\'\"]|\&\#0?3[4|9];)?\)'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need pipe in [4|9]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, in total we want to detect these:
34, 39, 034, 039
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but now i see, yes pipe is a mistake, although it should not cause a problem since character #\03| does not exist
I have removed the redudant pipe character, if that case was ever encountered then HTML is already broken |
$buffer = preg_replace($regex, 'style="$1: url(\'' . $base . '$2$3\')', $buffer); | ||
$regex_url = '\s*url\s*\(([\'\"]|\&\#0?3[49];)?(?!/|\&\#0?3[49];|' . $protocols . '|\#)([^\)\'\"]+)([\'\"]|\&\#0?3[49];)?\)'; | ||
$regex = '#style=\s*([\'\"])(.*):' . $regex_url . '#m'; | ||
$buffer = preg_replace($regex, 'style=$1$2: url($3' . $base . '$4$5$6)', $buffer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove '$6' from '$4$5$6)' and I can mark as a successful test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not remember now, but by looking at $6 it is the closing quote ? which is either ' or "
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whole regex:
#style=\s*([\'\"])(.*):\s*url\s*\(([\'\"]|\&\#0?3[49];)?(?!/|\&\#0?3[49];|' . $protocols . '|\#)([^\)\'\"]+)([\'\"]|\&\#0?3[49];)?\)#
#style=\s*(______)(__):\s*url\s*\((___________________)?(?!/|\&\#0?3[49];|' . $protocols . '|\#)(__________)(___________________)?\)#
I counted to five:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are six, did you test it without $6 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I tested on your examples. If I remove $5 too then ' or " are missing. Without $6 everything is OK.
(?!....) - it is not captured by regex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, i have taken time to look at it again and counted the blocks,
you are right, the $6 capturing block does not exist,
there are only 5 capturing blocks in the regular expressions, i will update the PR,
I missed it , as it does not cause error because $6 capturing block is always empty
I have removed the redudant $6 replacement of the 6th capturing block, as it does not the 6th capturing block, does not exist. |
I have tested this item ✅ successfully on b616e60 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/11266. |
1 similar comment
I have tested this item ✅ successfully on b616e60 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/11266. |
RTC Thanks @ggppdk This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/11266. |
Pull Request for Issue #11264 and issue: #7267
The SEF plugin attempts to make inline background url paths absolute but adding / or /jfolder/ to them
Example of broken cases:
the above will become:
which are obviously broken
Summary of Changes
Added handling of cases
Testing Instructions
Apply patch and at the bottom of index.php of protostar (just before </body> TAG) add:
after patch the will be no broken HTML
PS: there is almost zero performance impact to the regexp , we simply capture the quotes and use them, the regexp has no other changes