A site using repsonsive images (via the core "responsive_image" module) with multiplers is producing markup like this (via the core "media" module):
<source srcset="/sites/default/files/styles/ucbweb_media_width_400/public/stock-photos/CampanileWindow_1200_KeeganHouser.jpg?itok=tm8WkdEz 1x, /sites/default/files/styles/ucbweb_media_width_800/public/stock-photos/CampanileWindow_1200_KeeganHouser.jpg?itok=RvM2BU8N 2x" media="(min-width: 576px) and (max-width: 767px)" type="image/jpeg">
Notice how the "srcset" has two URLs with multipliers, joined by a comma.
After being processed by the Pathologic input filter, it looks like this:
<source srcset="http://ucbweb.lndo.site/sites/default/files/styles/ucbweb_media_width_400/public/stock-photos/CampanileWindow_1200_KeeganHouser.jpg?itok=tm8WkdEz%201x%2C%20/sites/default/files/styles/ucbweb_media_width_800/public/stock-photos/CampanileWindow_1200_KeeganHouser.jpg%3Fitok%3DRvM2BU8N%202x" media="(min-width: 576px) and (max-width: 767px)" type="image/jpeg">
It correctly put the full path on the first URL, but everything else after that got URL encoded, including the multipliers, spaces and comma - as if they were all part of the first URL.
The end result is a broken image!
If Pathologic is going to process "srcset", it should only modify the URLs, and not touch anything else in there.
Issue fork pathologic-3354345
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
dsnopekComment #4
edwtorba commentedI'm confirming that this issue is still happening on version 2.
Comment #7
dwwGreat, thanks! In principle, this sounds like it needs to happen and is heading in the right direction. No time for a super close review, but I see there are no new tests in the MR. I'm trying not to commit anything else here that doesn't have test coverage, tagging accordingly.
Thanks again, -Derek
Comment #9
prudloff commentedThe MR was splitting on
XXXwbut srcset also supports other syntax like2x. (See the spec here: https://html.spec.whatwg.org/multipage/images.html#srcset-attribute)I added tests for the different variants of the syntax.
I am not a huge fan of having to do
str_replace('="', '', $fixed_path)but avoiding it would require refactoring _pathologic_replace_individual().Comment #10
dwwThanks for fixing this, and for adding tests! I tried the GitLab test-only job, and although it failed, the output is pretty useless due to trying to view this stuff on the web. 😂 But I did a test-only run locally, and saw that the test indeed fails as expected:
I don't have 100% confidence in our existing test coverage, but it's encouraging that nothing broke with this change. 😅 There are a couple of existing 'srcset' cases in
tests/src/Kernel/PathologicTest.phpand those are still passing. 🎉Reviewing the actually changes... uhhh, yeah. 😂 This code is so cryptic, I'll be the first to admit it's not easy to modify or maintain. I appreciate https://git.drupalcode.org/project/pathologic/-/merge_requests/14/diffs?... since IMHO that helped make the resulting code more readable. I'm okay with doing this
srcsetcheck directly in_pathologic_replace()so we don't have to mess with the rest of what became_pathologic_replace_individual().However, I did push a few commits to do some superficial cleanup of the code in
_pathologic_replace(). The previous versions had a somewhat confusing mix of camelCaseVariables and snake_case. To match the rest of the code inpathologic.moduleI made everything snake_case. Also simplified a few things that had been split multi-line when they easily fit under 80 chars as 1 line. Finally, I added a comment about the special handling of srcset, inverted thatif (), and do an early return of_pathologic_replace_individual(). That way, what remains in_pathologic_replace()is only the srcset code, and it doesn't have to be indented an extra 2 spaces. 🤓The final pipeline is happy on all versions of core. It's passing phpstan level 5. All the other validation jobs are passing. I'm going to merge this.
Thanks again!
Comment #13
dww