@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

When creating a file by downloading a URI, truncate the length of the default name

Summary:
See <https://discourse.phabricator-community.org/t/embedding-external-images-url-show-error-for-long-urls/1339>.

When we download a file from a URI, we provide a default name based on the URI. However, if the URI is something like `http://example.com/very-very-very-....-long.jpg` with more than 255 characters, we may suggest a name which won't fit into the `name` column of `PhabricatorFile`.

Instead, suggest a default name no longer than 64 bytes.

Test Plan:
- Used the `{image ...}` example from the Discourse report locally; got an image with a truncated name.
- Used a normal `{image ...}`, got an image file with a normal name.

Reviewers: amckinley

Reviewed By: amckinley

Differential Revision: https://secure.phabricator.com/D19353

+10 -3
+10 -3
src/applications/files/storage/PhabricatorFile.php
··· 648 648 // just bail out. 649 649 throw $status; 650 650 } else { 651 - // This is HTTP 2XX, so use the response body to save the 652 - // file data. 651 + // This is HTTP 2XX, so use the response body to save the file data. 652 + // Provide a default name based on the URI, truncating it if the URI 653 + // is exceptionally long. 654 + 655 + $default_name = basename($uri); 656 + $default_name = id(new PhutilUTF8StringTruncator()) 657 + ->setMaximumBytes(64) 658 + ->truncateString($default_name); 659 + 653 660 $params = $params + array( 654 - 'name' => basename($uri), 661 + 'name' => $default_name, 655 662 ); 656 663 657 664 return self::newFromFileData($body, $params);