Problem/Motivation

Locale.module incorrectly flags URLs with a colon (":") in their paths as external, throwing an Exception.

Code in locale.module tries to detect whether a file is local or not before attempting to extract strings from it. If it determines that the file is not local, it throws an exception. The problem is how it determines whether the file is local or not -- it checks for the presence of a colon (":") to determine whether it is local, assuming that any file path that contains a colon must be external. Colons are valid for HTML paths and also are allowed in files in both MacOS and Linux filesystems, though, so this test is inaccurate. Fortunately, UrlHelper:: already contains static methods to determine whether a URL is local or external.

In my case, I hit this exception when trying to attach a theme's library to a render array, as the library included a JS file with a colon in the path:

$ cat games_theme.libraries.yml
[snip]
cg:tng-game:
  js:
    js/cg:tng-game.js: {}

Note: Per RFC 3986 Section 3.3 (Path), a colon is a valid character for inclusion in paths.

Steps to reproduce

  1. Define a library with a local JS file that contains a colon in path, as above
  2. Add that library as an #attachment to a page's render array
  3. Enable locale.module, clear cache
  4. Surf to the page in a browser
  5. Verify Exception: Only local files should be passed to _locale_parse_js_file()., although file is indeed a local file

Proposed resolution

Alter the code in locale.module to use UrlHelper::isExternal() and !UrlHelper::externalIsLocal() to properly determine whether the file should be read for string extraction.

https://git.drupalcode.org/project/drupal/-/merge_requests/6294

Remaining tasks

Write a unit test case for this, if needed.

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

Locale.module incorrectly flags URLs with a colon (":") in their paths as external, throwing an Exception. Fixed.

Issue fork drupal-3416586

Command icon 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

josephcheek created an issue. See original summary.

josephcheek’s picture

josephcheek’s picture

cilefen’s picture

Is this a duplicate issue?

krishna mishra’s picture

StatusFileSize
new520 bytes

Fix for exception fatal error is below patch

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.