feat: normalize 'to' field to https:// when no scheme provided#16
Merged
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
2 issues found across 2 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="internal/api/handlers.go">
<violation number="1" location="internal/api/handlers.go:77">
P1: The scheme prefix check is case-sensitive, so uppercase schemes like 'HTTP://' or 'HTTPS://' are not recognized and get a duplicate 'https://' prepended, producing a malformed URL.</violation>
</file>
<file name="internal/api/server_test.go">
<violation number="1" location="internal/api/server_test.go:80">
P2: Missing guard against empty Items slice before accessing Items[0]. If the create handler returns 201 without persisting the object, list.Items will be empty and this line will panic with an index-out-of-range error.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| http.Error(w, "'to' is required", http.StatusBadRequest) | ||
| return | ||
| } | ||
| if !strings.HasPrefix(to, "http://") && !strings.HasPrefix(to, "https://") { |
There was a problem hiding this comment.
P1: The scheme prefix check is case-sensitive, so uppercase schemes like 'HTTP://' or 'HTTPS://' are not recognized and get a duplicate 'https://' prepended, producing a malformed URL.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At internal/api/handlers.go, line 77:
<comment>The scheme prefix check is case-sensitive, so uppercase schemes like 'HTTP://' or 'HTTPS://' are not recognized and get a duplicate 'https://' prepended, producing a malformed URL.</comment>
<file context>
@@ -69,10 +69,14 @@ func (h *Handlers) create(w http.ResponseWriter, r *http.Request) {
http.Error(w, "'to' is required", http.StatusBadRequest)
return
}
+ if !strings.HasPrefix(to, "http://") && !strings.HasPrefix(to, "https://") {
+ to = "https://" + to
+ }
</file context>
Suggested change
| if !strings.HasPrefix(to, "http://") && !strings.HasPrefix(to, "https://") { | |
| if !strings.HasPrefix(strings.ToLower(to), "http://") && !strings.HasPrefix(strings.ToLower(to), "https://") { |
|
|
||
| list := &decositesv1alpha1.DecoRedirectList{} | ||
| _ = fc.List(context.Background(), list) | ||
| if list.Items[0].Spec.To != "https://www.example.com" { |
There was a problem hiding this comment.
P2: Missing guard against empty Items slice before accessing Items[0]. If the create handler returns 201 without persisting the object, list.Items will be empty and this line will panic with an index-out-of-range error.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At internal/api/server_test.go, line 80:
<comment>Missing guard against empty Items slice before accessing Items[0]. If the create handler returns 201 without persisting the object, list.Items will be empty and this line will panic with an index-out-of-range error.</comment>
<file context>
@@ -58,6 +58,30 @@ func TestCreate_HappyPath(t *testing.T) {
+
+ list := &decositesv1alpha1.DecoRedirectList{}
+ _ = fc.List(context.Background(), list)
+ if list.Items[0].Spec.To != "https://www.example.com" {
+ t.Fatalf("expected to=https://www.example.com, got %s", list.Items[0].Spec.To)
+ }
</file context>
Suggested change
| if list.Items[0].Spec.To != "https://www.example.com" { | |
| if len(list.Items) != 1 { | |
| t.Fatalf("expected 1 DecoRedirect, got %d", len(list.Items)) | |
| } | |
| if list.Items[0].Spec.To != "https://www.example.com" { |
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.
Summary by cubic
Normalize the redirect "to" field by trimming whitespace and defaulting to https:// when no scheme is provided. This ensures stored redirects are valid and consistent.
toand prependhttps://if no scheme is present in thecreatehandler.https://....Written for commit 3321246. Summary will update on new commits. Review in cubic