Fix redirect encoding#444
Merged
Merged
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideRefactors redirect URL encoding to use parse_url and targeted quote encoding while preserving fragments and queries, and extends tests to cover URLs with fragments containing UTF-8 characters. Flow diagram for updated getEncodedRedirectUrl encoding logicflowchart TD
A[Input redirectUrl] --> B[parse_url redirectUrl]
B --> C{parsedUrl path set?}
C -- yes --> D[str_replace quotes in parsedUrl path
with %22 and %27]
C -- no --> E[Leave path as null]
D --> F[Build base URL:
scheme://host + path]
E --> F
F --> G{parsedUrl query set?}
G -- yes --> H[Append ?query]
G -- no --> I[Skip query]
H --> J{parsedUrl fragment set?}
I --> J
J -- yes --> K[Append #fragment]
J -- no --> L[Skip fragment]
K --> M[Return url]
L --> M[Return url]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The new
getEncodedRedirectUrlimplementation assumesparse_urlalways returnsscheme,host, andpath, which will trigger notices or malformed URLs for inputs like relative URLs, scheme-less URLs, or URLs without a path; consider adding guards forparse_url === falseand missing components before concatenation. - The reconstructed URL currently drops other possible URL parts such as
port,user, andpass; if those are valid inputs in this context, you may want to include them when rebuilding the URL. - Directly concatenating
$parsedUrl['path']without defaulting to an empty string can produce an undefined index notice when the original URL has no path (e.g.,http://example.com); consider using$parsedUrl['path'] ?? ''in the concatenation.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new `getEncodedRedirectUrl` implementation assumes `parse_url` always returns `scheme`, `host`, and `path`, which will trigger notices or malformed URLs for inputs like relative URLs, scheme-less URLs, or URLs without a path; consider adding guards for `parse_url === false` and missing components before concatenation.
- The reconstructed URL currently drops other possible URL parts such as `port`, `user`, and `pass`; if those are valid inputs in this context, you may want to include them when rebuilding the URL.
- Directly concatenating `$parsedUrl['path']` without defaulting to an empty string can produce an undefined index notice when the original URL has no path (e.g., `http://example.com`); consider using `$parsedUrl['path'] ?? ''` in the concatenation.
## Individual Comments
### Comment 1
<location path="src/Backend/Modules/Pages/Engine/Model.php" line_range="1556-1560" />
<code_context>
+ $parsedUrl['path'] = str_replace(['"', '\''], ['%22', '%27'], $parsedUrl['path']);
+ }
+
+ $url = $parsedUrl['scheme'] . '://' . $parsedUrl['host'] . $parsedUrl['path'];
+ if (isset($parsedUrl['query'])) {
+ $url .= '?' . $parsedUrl['query'];
+ }
+ if (isset($parsedUrl['fragment'])) {
+ $url .= '#' . $parsedUrl['fragment'];
}
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Preserve optional URL components like port, user/pass and guard against missing path.
This reconstruction omits `port`, `user`, `pass`, and assumes `path` is always set. For example, `https://user:pass@example.com:8443/foo` would lose credentials and port, and URLs without a path would hit an undefined index on `$parsedUrl['path']`. Please build `$url` conditionally from all present components (user/pass, host, port, path), and treat a missing path as an empty string.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
tijsverkoyen
reviewed
Jun 4, 2026
tijsverkoyen
approved these changes
Jun 4, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://next-app.activecollab.com/108877/my-work?modal=Task-253942-4609
Summary by Sourcery
Adjust redirect URL encoding to correctly handle quotes while preserving query strings and fragments.
Bug Fixes:
Tests: