UrlHelper::encodePath() doesn't support Windows paths

Created on 6 March 2015, over 10 years ago
Updated 31 July 2025, 2 days ago

I never used Drupal on windows before but now I just wanted to test my module on clean drupal and found out that I just cant use

drupal_add_js(MY_MODULE_ROOT_REL. '\\js\\somejs.js'); 

// or

drupal_add_js(MY_MODULE_ROOT_REL. '/js/somejs.js');

I defined my custom constants as

/**
 * Define root constant. (An absolute path: /home/var/www/)
 * This is used to prevent using drupal_get_path() cause __DIR__ is much faster and
 * don't use database connection to find out there this module is located.
 * @note requires PHP 5.3+
 */
define('MY_MODULE_ROOT', __DIR__);

/**
 * Relative path to this module (sites/default/....)
 */
define('MY_MODULE_ROOT_REL', str_replace(DRUPAL_ROOT. DIRECTORY_SEPARATOR, '', MY_MODULE_ROOT));

Disclaimer:
I know that Windows is not platform for develop but I think it is not good if Drupal won't work on windows too.
I know about drupal_get_path() but I don't want to use database connection just to find out the path to my module (I use drupal bootstrap_database layer and only include constant.inc files)

πŸ› Bug report
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component

file system

Created by

πŸ‡·πŸ‡ΊRussia Cadila

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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.

  • πŸ‡¦πŸ‡ΊAustralia kim.pepper πŸ„β€β™‚οΈπŸ‡¦πŸ‡ΊSydney, Australia

    Reviewing as part of Bug Smash Initiative. As per the comment in #25 marking this as PMNMI.

Production build 0.71.5 2024