Add file_exists() to _locale_parse_js_file() to prevent PHP warning

Created on 4 October 2012, about 12 years ago
Updated 2 May 2023, over 1 year ago

Problem/Motivation

Some times a theme or module may attempt to add a JavaScript file that does not actually exist. When this happens, _locale_parse_js_file() causes a PHP warning whenever the cache is cleared and it tries to parse the non-existing file.

In the following example the theme foo attempts to add the file bar.js.

Warning: file_get_contents(sites/all/themes/foo/bar.js): failed to open stream: No such file or directory in file_get_contents() (line 1488 of /var/www/drupal/includes/locale.inc).

This is of course not a common scenario, but it can be quite bothersome when working with themes and modules out of ones own control.

Proposed resolution

Adding a simple file_exists() before file_get_contents() in locale.inc's _locale_parse_js_file() fixes the problem without any side effects. A patch containing this fix is attached.

Remaining tasks

Rework Tests For D8 so that they pass #52
Commit D8 patch

RTBC patch for D7 #33
Commit D7 patch

User interface changes

None.

API changes

None.

๐Ÿ› Bug report
Status

Needs work

Version

10.1 โœจ

Component
Localeย  โ†’

Last updated 4 days ago

Created by

๐Ÿ‡ฉ๐Ÿ‡ฐDenmark yosh

Live updates comments and jobs are added and updated live.
  • Needs backport to D7

    After being applied to the 8.x branch, it should be considered for backport to the 7.x branch. Note: This tag should generally remain even after the backport has been written, approved, and committed.

Sign in to follow issues

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.71.5 2024