FileUrlGenerator::transformRelative() edge case errors

Created on 2 July 2018, almost 6 years ago
Updated 5 January 2024, 6 months ago

Problem/Motivation

On some of my sites, I have twice experienced faulty links to generated CSS and JS.

For some reason, the links to the generated files were malformed, i.e.:

<link rel="stylesheet" href=":443/sites/default/files/css/css_6u7oFEr4OkoMAF9qdJQzJlzRk552XMusS-n-KvqQkO0.css?pa9m7y" media="all" />

A cache rebuild made the problem disappear, and I haven't been able to track down a real root cause for this.

But the problem made me take a closer look at FileUrlGenerator::transformRelative() and noticed it errors on some unusual, edge case input.

I created a patch fixing these edge case errors and extends the test cases with nine new test data set covering these edge cases.

Steps to reproduce

Here are the edge cases I have identified:

  • https://example.com:443/page on a https://example.com/something request is transformed into :443/page. Although it is unusual to supply the port number for the default port, it is not an invalid URL. This could be my original problem, although I have no clue why it would end up in this case.
  • http://example.com:1337/page on a http://example.com/something request is transformed into /page. So, referencing a URL on a different port when being on a default port transform into a relative URL. Although very unusual, it is at least a theoretical possibility that someone deliberately would reference something on a different port.
  • http://example.com on a http://example.com/something request is transformed into an empty string. Although this is probably not the intended use case of the function, it would make the function more robust to handle that case as well.

Proposed resolution

The patch solves the edge cases by hardening the existing regular expression.

Remaining tasks

Code review

User interface changes

NA

API changes

NA

Data model changes

NA

Release notes snippet

NA

πŸ› Bug report
Status

Fixed

Version

10.2 ✨

Component
BaseΒ  β†’

Last updated about 3 hours ago

Created by

πŸ‡©πŸ‡°Denmark arnested

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024