Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebDAV: File paths with "#" characters are truncated #1828

Open
nextgovitAS opened this issue Nov 5, 2024 · 0 comments
Open

WebDAV: File paths with "#" characters are truncated #1828

nextgovitAS opened this issue Nov 5, 2024 · 0 comments

Comments

@nextgovitAS
Copy link

nextgovitAS commented Nov 5, 2024

Bug Report

Q A
Flysystem Version 3.29.0
Adapter Name webdav
Adapter version 3.29.0

Description

When using league/flysystem-webdav, file paths that include the # character are truncated, causing unexpected behavior. This issue arises because the library applies parse_url() to paths, which interprets # as a fragment identifier and discards everything following it. For example, a file named file#example.txt is processed as file, resulting in data loss and errors when attempting to interact with files that contain # in their names.

Steps to Reproduce

  1. Create a file in WebDAV storage with a # in its name, e.g., file#example.txt.
  2. Attempt to list the contents of the directory using the listContents function.
  3. Observe that the file name is truncated at the #, leading to failed operations.

Expected Behavior

The library should treat # as a valid character within the file path and not interpret it as a URL fragment identifier. The entire file name, including the #, should be preserved.

Actual Behavior

The library truncates the path at the # character due to parse_url() processing, which results in incorrect file paths.

Suggested Fix

I modified the code in WebDAVAdapter as follows to address this issue:

Old:

public function listContents(string $path, bool $deep): iterable
{
  [...]
  $path = (string) parse_url(rawurldecode($path), PHP_URL_PATH);
  [...]

New:

public function listContents(string $path, bool $deep): iterable
{
  [...]
  $rawUrl = rawurldecode($path);
  $path = (string) parse_url($rawUrl, PHP_URL_PATH);
  $fragment = parse_url($rawUrl, PHP_URL_FRAGMENT);
  if (is_string($fragment)) {
    $path .= '#' . $fragment;
  }
  [...]

With this change, paths are correctly reconstructed to include the # fragment, preserving the original file names.

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

No branches or pull requests

1 participant