Skip to content

ext/ftp: Add optional MLSD fact name normalization - #25808

Open
WoodenGolem wants to merge 1 commit into
php:masterfrom
WoodenGolem:ftp-mlsd-normalize-fact-names
Open

WoodenGolem wants to merge 1 commit into
php:masterfrom
WoodenGolem:ftp-mlsd-normalize-fact-names

Conversation

@WoodenGolem

Copy link
Copy Markdown

LLM disclosure: This PR description was drafted with AI assistance.

Summary

RFC 3659 treats MLSD fact names as case-insensitive, but PHP array keys are
case-sensitive. ftp_mlsd() currently returns fact names in the casing
supplied by the FTP server, which can break callers when that casing changes
(see #18064).

This PR adds an optional bool $normalize_fact_names = false parameter.
Calls without the parameter, and calls passing false, retain the existing
behavior. Passing true lowercases ASCII letters in fact names before using
them as array keys. Non-ASCII bytes, filenames, and fact values are unchanged.

For example, given the server response:

Type=FiLe;SIZE=51574;UNIX.mode=0644; example.jpg

ftp_mlsd($ftp, '.', true) includes an entry equivalent to:

[
    'name' => 'example.jpg',
    'type' => 'FiLe',
    'size' => '51574',
    'unix.mode' => '0644',
]

Collisions and compatibility

In the opt-in mode, server-supplied Name/name facts are ignored so they
cannot overwrite PHP's separate name key for the pathname. If multiple
fact names normalize to the same key (such as Type and type), the last
fact wins, matching the existing handling of repeated identical fact names.
These rules do not change the default mode.

This intentionally does not normalize type values: RFC 3659 defines
those values as case-insensitive, but changing values is outside the scope of
this option.

Tests

The local FTP test server covers default/false equivalence, mixed-case and
lowercase keys, unchanged filenames and values, Name/name, collisions,
non-ASCII bytes, empty and missing directories, and malformed responses.

  • Debug build with OpenSSL and FTP-SSL enabled: 67/67 FTP tests passed,
    none skipped (Docker --network none).
  • ZTS build: 4/4 MLSD tests passed.

Docker network isolation prevents the host's VPN DNS search domain from
resolving a deliberately invalid hostname used by an existing FTP test.

Documentation

A corresponding php/doc-en update is prepared locally for a separate PR
after the API shape is confirmed. Applications, including Nextcloud, must
explicitly opt in to use the new parameter; this change alone does not alter
their behavior.

Related: #18064; RFC 3659, sections 7.4–7.5.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant