Skip to content

Beautiful Open-Source Form Builder

Address PR review feedback: encode unsigned_url and remove unused isEncoded method

Cursor Agentdb936f050844
diff --git a/api/app/Service/Forms/FormSubmissionFormatter.php b/api/app/Service/Forms/FormSubmissionFormatter.php
index 20e9ab855..2347e47f7 100644
--- a/api/app/Service/Forms/FormSubmissionFormatter.php
+++ b/api/app/Service/Forms/FormSubmissionFormatter.php
@@ -250,9 +250,10 @@ class FormSubmissionFormatter
}
$field['email_data'] = collect($data[$field['id']])->map(function ($file) use ($formId) {
$splitText = explode('.', $file);
+ $encodedFilename = FilenameUrlEncoder::encode($file);
return [
- 'unsigned_url' => route('open.forms.submissions.file', [$formId, $file]),
+ 'unsigned_url' => route('open.forms.submissions.file', [$formId, $encodedFilename]),
'signed_url' => $this->getFileUrl($formId, $file),
'label' => Str::limit($file, 20, '[...].' . end($splitText)),
];
diff --git a/api/app/Service/Storage/FilenameUrlEncoder.php b/api/app/Service/Storage/FilenameUrlEncoder.php
index f26b52bdb..ceea7deab 100644
--- a/api/app/Service/Storage/FilenameUrlEncoder.php
+++ b/api/app/Service/Storage/FilenameUrlEncoder.php
@@ -50,33 +50,4 @@ class FilenameUrlEncoder
return $decoded;
}
-
- /**
- * Check if a string appears to be base64url encoded.
- *
- * This helps with backward compatibility - if a filename doesn't look
- * like it's encoded, we can handle it as a raw filename.
- *
- * @param string $value The value to check
- * @return bool True if the value appears to be base64url encoded
- */
- public static function isEncoded(string $value): bool
- {
- // Base64url only contains alphanumeric, dash, and underscore
- // Real filenames typically have dots and other characters
- if (!preg_match('/^[A-Za-z0-9_-]+$/', $value)) {
- return false;
- }
-
- // Try to decode and check if result is valid UTF-8
- $decoded = self::decode($value);
-
- // If decoded equals input, it wasn't really encoded
- if ($decoded === $value) {
- return false;
- }
-
- // Check if the decoded value is valid UTF-8
- return mb_check_encoding($decoded, 'UTF-8');
- }
}
diff --git a/api/tests/Unit/Service/Storage/FilenameUrlEncoderTest.php b/api/tests/Unit/Service/Storage/FilenameUrlEncoderTest.php
index eec1f7cc0..02eacae23 100644
--- a/api/tests/Unit/Service/Storage/FilenameUrlEncoderTest.php
+++ b/api/tests/Unit/Service/Storage/FilenameUrlEncoderTest.php
@@ -96,37 +96,6 @@ describe('FilenameUrlEncoder', function () {
});
});
- describe('isEncoded', function () {
- it('returns true for encoded filenames', function () {
- $original = 'image-(1)_abc.jpg';
- $encoded = FilenameUrlEncoder::encode($original);
-
- expect(FilenameUrlEncoder::isEncoded($encoded))->toBeTrue();
- });
-
- it('returns false for raw filenames with special characters', function () {
- $filename = 'image-(1)_abc.jpg';
-
- expect(FilenameUrlEncoder::isEncoded($filename))->toBeFalse();
- });
-
- it('returns false for filenames with dots', function () {
- $filename = 'document.pdf';
-
- expect(FilenameUrlEncoder::isEncoded($filename))->toBeFalse();
- });
-
- it('returns false for simple alphanumeric that matches itself when decoded', function () {
- // A string that is valid base64url but decodes to gibberish
- $simple = 'abc123';
-
- // This might or might not be considered encoded depending on decode result
- // The key is it should be safe to use
- $result = FilenameUrlEncoder::isEncoded($simple);
- expect($result)->toBeBool();
- });
- });
-
describe('roundtrip', function () {
it('handles various S3-safe filenames correctly', function () {
$testCases = [