-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance redirect URL handling and MentionParser functionality (#639)
- Updated the `redirect_url` validation in `UserFormRequest` to accept strings instead of just max length. - Modified `MentionParser` to include a `urlFriendlyOutput` method, allowing for URL encoding of special characters in parsed values. - Adjusted the `PublicFormController` to utilize the new `urlFriendlyOutput` method for redirect URLs. - Created a migration to change the `redirect_url` field type in the database from string to text, accommodating longer URLs. - Added tests to ensure proper handling of long redirect URLs and the functionality of the new URL-friendly output feature in `MentionParser`. This update improves the flexibility and robustness of form handling and URL processing.
- Loading branch information
1 parent
d09b5c4
commit ea4cd85
Showing
6 changed files
with
115 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
api/database/migrations/2024_12_05_121609_change_redirect_url_to_text_in_forms_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class () extends Migration { | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::table('forms', function (Blueprint $table) { | ||
$table->text('redirect_url')->nullable()->change(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::table('forms', function (Blueprint $table) { | ||
$table->string('redirect_url')->nullable()->change(); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
test('form accepts long redirect urls', function () { | ||
$this->withoutExceptionHandling(); | ||
$user = $this->actingAsUser(); | ||
$workspace = $this->createUserWorkspace($user); | ||
$form = $this->createForm($user, $workspace); | ||
|
||
// Create a very long URL (more than 255 characters) | ||
$longUrl = 'https://example.com/?' . str_repeat('very-long-parameter=value&', 50); | ||
|
||
$this->putJson(route('open.forms.update', $form->id), array_merge($form->toArray(), [ | ||
'redirect_url' => $longUrl | ||
]))->assertStatus(200); | ||
|
||
expect($form->fresh()->redirect_url)->toBe($longUrl); | ||
}); | ||
|
||
test('form accepts null redirect url', function () { | ||
$user = $this->actingAsUser(); | ||
$workspace = $this->createUserWorkspace($user); | ||
$form = $this->createForm($user, $workspace); | ||
|
||
$this->putJson(route('open.forms.update', $form->id), array_merge($form->toArray(), [ | ||
'redirect_url' => null | ||
]))->assertStatus(200); | ||
|
||
expect($form->fresh()->redirect_url)->toBeNull(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters