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
- Define a library with a local JS file that contains a colon in path, as above
- Add that library as an #attachment to a page's render array
- Enable locale.module, clear cache
- Surf to the page in a browser
- 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.
Merge request link
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.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | 3416586-Fix-exception-only-local.patch | 520 bytes | krishna mishra |
Issue fork drupal-3416586
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
josephcheekComment #4
josephcheekMR at https://git.drupalcode.org/project/drupal/-/merge_requests/6294
Comment #5
cilefen commentedIs this a duplicate issue?
Comment #6
krishna mishra commentedFix for exception fatal error is below patch