Sitelet https://github.com/xdebug/xdebug/pull/1044
Skip to content

Fix file URI handling for Shift_JIS filenames on Windows - #1044

Open
chimorium wants to merge 2 commits into
xdebug:masterfrom
chimorium:handle-shiftjis-filename
Open

chimorium wants to merge 2 commits into
xdebug:masterfrom
chimorium:handle-shiftjis-filename

Conversation

@chimorium

@chimorium chimorium commented Nov 2, 2025 •

Copy link
Copy Markdown

Summary

This pull request improves file path handling in Xdebug on Windows by ensuring proper conversion of Shift_JIS-encoded filenames to UTF-8.
Previously, Shift_JIS-encoded paths could not be correctly represented as file URIs, which caused debugger connection failures and incorrect file references when working with non-UTF-8 environments (e.g., PHP source files in Shift_JIS).

Background

On Windows systems using Shift_JIS locale, __FILE__ and related filenames in PHP source code are encoded in Shift_JIS.
Xdebug expected these to be UTF-8, leading to garbled paths or invalid URIs (e.g., during DBGp communication).

This patch adds encoding detection and proper conversion before generating file URIs.

Changes

  1. src/base/base.c
    Added UTF-8 filename preparation for Windows builds:
#if PHP_WIN32
	if (op_array->filename) {
		char *utf8_filename = xdebug_prepare_filename(ZSTR_VAL(op_array->filename));
		if (utf8_filename) {
			xdebug_lowercase_drive_letter(utf8_filename);
			char *utf8_filename_url = xdebug_path_to_url(/sitelet?url=https%3A%2F%2Fgithub.com%2Fxdebug%2Fxdebug%2Fpull%2Futf8_filename%2C%2520strlen%28utf8_filename));
			if (utf8_filename_url) {
				op_array->filename = zend_string_init(utf8_filename_url, strlen(utf8_filename_url), 0);
				free(utf8_filename_url);
			}
			free(utf8_filename);
		}
	}
#endif
  1. src/debugger/handler_dbgp.c
    Replaced manual URL encoding with:
xdstrdup(XDEBUG_STR_VAL(XXX))
  1. src/lib/usefulstuff.c
    Added new helper functions:
  • xdebug_is_valid_utf8(const char *str)
  • xdebug_is_valid_shiftjis(const char *str)
  • xdebug_is_valid_encoding(const char *str)
    → Detects UTF-8, Shift_JIS, or Unknown
  • xdebug_shiftjis_to_utf8(const char *sjis_str)
    → Converts Shift_JIS string to UTF-8 using MultiByteToWideChar / WideCharToMultiByte
  • xdebug_prepare_filename(const char *filename)
    → Converts filename to UTF-8 if necessary
  • xdebug_lowercase_drive_letter(char *fileuri)
    → Normalizes drive letter casing in file URIs

Impact

  • Correct handling of Shift_JIS-encoded PHP source filenames on Windows
  • Prevents invalid file URIs in DBGp communication
  • No impact on non-Windows or UTF-8 environments (guarded with #if PHP_WIN32)

Testing

  • Verified Shift_JIS paths on Windows
  • Confirmed proper conversion and URI generation

Credits

Authored by @chimorium
Discussed and refined with ChatGPT (context: Shift_JIS path issue in Xdebug)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants