Closed (fixed)
Project:
Pathologic
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
17 Mar 2022 at 03:26 UTC
Updated:
26 Apr 2023 at 01:34 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
jedgar1mx commentedComment #3
dwwHrm, bummer. I specifically did *not* commit #2418369: Internal URL handling (language prefixes, base://, ...) since it seemed to be not totally bullet-proof for country codes. #2993935: Support for srcset attribute seems unlikely to have caused this. #2692641: Convert href to the aliased URL if possible might be the culprit, but that seems a bit unlikely, too. :(
Can you provide the resulting
<img>source from the page views for the two cases? And the raw value in the text prior to the filter running?Do you really need #2718473: Dynamic routes in image styles break under pathologic, instead? Did you used to apply any pathologic patches and are no longer applying them after the update?
We need more info here on how to reproduce this before anyone can come up with a fix.
Thanks/sorry,
-Derek
Comment #4
jedgar1mx commentedThanks for the fast replay @dww.
Here are the
<img>source for both cases./sites/detroitmi.localhost/files/2022-02/detroit-future-fund-795x795.jpges/sites/detroitmi.localhost/files/2022-02/detroit-future-fund-795x795.jpgI don't use any patches on pathologic and I'm on drupal 9.3.8.
Comment #5
dwwThanks @jedgar1mx. Can you also provide what the source from the body field looks like? Or whatever text is being filtered to produce these
<img>tags?Comment #6
jedgar1mx commentedHere is the body field.
Comment #7
jedgar1mx commentedAlso we did try both full paths and relative paths and it behave the same way.
Comment #8
biguzis commentedAlso, links that are used as absolute, like https://example.com/en/node/1, becomes to https://example.com/en/en/node/1 with double language prefix.
Comment #9
dwwUgh, bummer. I now have almost no confidence in the existing test suite. All of this should have been caught by tests, but that clearly didn't happen. I suspect #2692641: Convert href to the aliased URL if possible is the culprit. This patch reverts that change. Does this fix your sites?
Comment #10
nickdjmRan into the same issue. Tested #9 and it resolves it.
Comment #11
jedgar1mx commentedHey @dww, is it better to stay on
alpha2or upgrade toalpha3and apply the patch? Anything mayor thatalpha3includes?Comment #12
biguzis commented#9 solves issue.
Comment #13
aiphesOn D93.13 + 8.x-1.0-alpha3 , paths images (PNG, not SVG) are broken if I enabled the input filter.
Applying the patch works.
Comment #14
unstatu commentedI came to this issue because I had the same error. However, I have approached it in a different way:
Can't we do the same in the _pathologic_replace function? Or am I missing some side effect?
Comment #15
qusai taha commentedPatch #9 working fine with me
Comment #16
thatguy commentedMy relative and absolute links added through text editor started showing the double language prefix when updating to 8.x-1.0-alpha3. Patch in #9 fixed the issue and should be merged and released as a new version as soon as possible.
Comment #17
urashima82 commentedI tried the patch #9 but it removed language prefix from my links in paragraphs.
By the way, I was facing a similar problem with PDF files and I solved it using the dedicated hook :
Hope it could help !
Comment #18
mark_fullmerAttempting to sum up the discussion up to this point:
1. The basic problem is that Pathologic now adds a language prefix to links to files on sites where Drupal's multilingual features are enabled.
2. The patch in #9 has been reported to fix the issue for a number of folks (10, 12, 13, 16).
3. There is currently no test coverage that verifies the fix.
4. One comment (#8) reported the same problem on absolute links ("Also, links that are used as absolute, like https://example.com/en/node/1, becomes to https://example.com/en/en/node/1 with double language prefix.")
5. Another comment *#17) reported that the patch in #9 actually removed language prefixes from links within paragraphs (assuming this isn't referring to the Paragraphs module).
Based on the above, I will work on the following:
1. Create test coverage that establishes the expected + actual output of linked files, linked absolute paths, and linked relative paths when multilingual features are enabled.
2. Provide that as a standalone patch to demonstrate current failure.
3. Add a separate patch that includes the refactor from #9 and establish whether or that that handles all 3 scenarios correctly.
Comment #19
mark_fullmerComment #20
mark_fullmerOkay, test coverage!
The test scaffolding was largely derived from Drupal core's
FileOnTranslatedEntityTestandPathLanguageTesttests. I then added logic to enable Pathologic on a text format. The test creates a node with a link (to a file path, to another node) and then creates a translation of that node. It verifies that the link on the translated node does not have the language prefix.There are two patches:
The patches apply cleanly to both the 8.x-1.x and 2.0.x branches, and upon review & approval, should be merged into both branches.
Comment #23
mark_fullmerIt looks like the syntax of the test doesn't work in the context of Drupal 9.5.x (I constructed it using 10.x). I'd like to run the same patches on the 2.0.x branch to verify that I'm not getting a different result locally than the test runner. Assuming not, then I'll look into different test logic that works with Drupal 9.5.x.
Comment #26
mark_fullmerLooks like my local testing environment didn't care that drupalGet() didn't start with a /, whereas testbot does? (Tipped off from https://www.drupal.org/project/commerce/issues/2855587#comment-11956902).
Trying one more time...!
There are two patches:
The patches apply cleanly to both the 8.x-1.x and 2.0.x branches, and upon review & approval, should be merged into both branches.
Comment #29
dwwThanks for diving into this mess! 😅 See also #3157085: Convert tests/src/Functional/PathologicTest.php to a Kernel test, which I'd love to move forward as we try to get the test coverage here into better shape...
I don't have time right now to dig deeper into what you're doing here, but hopefully soon.
Cheers,
-Derek
Comment #30
mark_fullmerAlright, inspecting the artifacts on the d.o test runner, I see that it's adding a
subdirectory/prefix to the URL; this is not specific to Pathologic's processing of relative URLs. With that in mind, I did one more refactor to the test that explicitly checks that thehrefwe want (/sites/default/file.png) is on the page, and also explicitly checks that the language prefix ( (/fr/sites/default/file.png) is not.Sorry for all the noise, everyone!
Comment #32
dwwThanks for keeping this moving! Yeah, the testbot uses a subdir, partly to flesh out bugs that are hidden on sites that don't use them. 😉
So the only "fix" to get the test working is to revert the 2-line change from #2692641: Convert href to the aliased URL if possible, huh? That's all patch #9 is. Seems we should probably re-open that issue. I should have required test coverage over there before we committed it, since I'm sure reverting will piss off the non-multilingual folks that were so excited about that issue. 😬
Meanwhile, the full patch says "6.66 KB", so we can't possibly commit that, especially not on Ash Wednesday! 😂
Since this is my first time reviewing your test writing, here's a close review as I see things:
Do we care that the markup is from
oliverofor some reason? I'd much rather test withstarkif possible. It's much more generic, less fragile for testing, is compatible across way more branches, probably makes the tests a bit faster, etc.This is slow and expensive. Especially inside a
setUp()method that's called over and over again in aFunctionaltest for eachtest*()method. I'd much rather do something like this:Ditto here. I think this can be something like:
Probably this, too, although a quick spot check, and for some reason, most core tests I just looked at which deal with translation do this via the UI... 🤔
And for all of this, should we move
_pathologic_build_format()out of PathologicTest.php, turn it into a test trait, and share it so we can easily make filters that do what we want instead of having to click it together in the UI insetUp()like this?We can add the
: voidfor this.If you're using
drupalCreateNode()(yay!) you don't need thedrupalGet().All this can be:
Or, if you want to modify stuff in the translation, you can just do something like:
Perhaps to a fault, but as you can see, I get really hung up on test performance, especially in
Functionaltests (even more so inFunctionalJavascript). 😅 Given how much CO2 we burn for all the computing cycles for all the automated tests that run, and for our own lives while doing test-driven dev, I'd rather our test suite be as fast as possible.So I wonder if we can merge these two tests, create all the links we need to test in the smallest number of nodes, fetch the output once, and make as many assertions as possible about the links on the page? Basically, think of every
drupalGet()orsubmitForm()in aFunctionaltest as a $50,000 expense over time. 😅 I try to minimize those...Reflecting on my last point -- does this need to be a
Functionaltest at all? Can't we generate the content, run the filter, and check the output in aKerneltest? Why do we need a test browser for this at all?Phew! Ended up being a long list. But overall, this is great work, and I love that you're providing solid test coverage of what's happening in here! 💗 Curious to hear your thoughts.
Thanks again!
-Derek
Comment #33
mark_fullmerThanks, so much, for the thoughtful and thorough feedback, Derek! Regarding making tests run efficiently, you have a kindred spirit here. I've added tweaks to our team's Drupal distribution test suite to minimize the number of setups it does and use a core patch that allows FunctionalJS setups from an existing database rather than a fresh install. Balanced with that, I also tend to approach writing tests as self-documenting 'steps to reproduce' with the aim of being more accessible to other developers.
There were a few reasons I was thinking this particular test should be Functional rather than Kernel, and UI-based:
1. As an integration test of Drupal's multilingual functionality, I think it makes more sense to put this through the Drupal pipeline to the rendered page. This allows us to orchestrate Drupal's text filter rendering with Drupal's content translation in the same way a site builder would, and in the future would allow testing integration with other things (such as other text filters designed to modify links) more directly, rather than mocking them.
2. Because it involves Drupal's multilingual functionality, which fewer contributors are familiar with, it will be easier for other contributors to understand what is going on in the test if more of the multilingual configuration actions step through the UI.
3. From a purely technical perspective, it wasn't immediately clear to me how a Kernel test would do the equivalent of visiting
/node/1vs./fr/node/1.Other suggestions: 100%!
- Stark instead of Olivero (I'd started with Stark, then switched to debug HTML output, then forgot to switch back!)
- One test instead of two (I'd done two for DX, but we can surely maintain good DX in one test)
- Reduce the number of nodes we need to create (follows from the above)
Would it make more sense to create follow-up task for relocating
_pathologic_build_format()into a test trait (or better: FunctionalTestBase method?), since it would require differences between the 8.x-1.x and 2.0.x patches? Or should we do that just for the 2.0.x branch?Comment #34
mark_fullmerAdding to what dww said in #32 about core tests for translation using the UI, I took a look at core's tests for testing translated output (mostly in the content_translation module). I didn't find a good model of a core Kernel test for content translation. That's not to say it can't be done, and I'm not opposed to using Kernel tests; just that we don't have a good paradigm to work from.
But taking it from another perspective -- looking at how we are approaching the Kernel tests in #3157085: Convert tests/src/Functional/PathologicTest.php to a Kernel test -- if the test coverage we're trying to provide is to confirm that the Pathologic text filter is *not* adding language prefixes to file paths or bare node paths, and since check_markup() takes an optional language code parameter, would it be sufficient test coverage to do something like the following (non-tested-code)?
Comment #35
mark_fullmerUpdate: the maintainers discussed this, and given the value of providing a Drupal 10-compatible release sooner (see #3343541: Plan for new Pathologic releases), one that includes reverting the change that led to this issue in the first place, we have decided to:
1. Merge this issue, with its working Functional tests now.
2. Cut a Drupal 10-compatible release from the 2.0.x branch
3. Finish work on #3157085: Convert tests/src/Functional/PathologicTest.php to a Kernel test to convert other existing tests to Kernel-based.
4. Create a follow-up issue to convert the Functional test added here to a Kernel-based test.
Comment #36
dwwYup, I'm on it. Just found some other test badness that we need to fix, first: #3353557: PathologicUITest should not be testing the Internet. As soon as that's resolved, I'm going to proceed here.
Thanks!
-Derek
Comment #39
dwwCommitted to 2.0.x and cherry-picked to 8.x-1.x. Pushed to both branches. Thanks!
Comment #40
dwwp.s. The follow-up is a child of this issue, but linking here for more visibility:
#3353562: Convert PathologicLanguageTest to a Kernel test