Skip to content

feat: normalize 'to' field to https:// when no scheme provided#16

Merged
igoramf merged 1 commit into
mainfrom
feat/normalize-redirect-to
May 22, 2026
Merged

feat: normalize 'to' field to https:// when no scheme provided#16
igoramf merged 1 commit into
mainfrom
feat/normalize-redirect-to

Conversation

@igoramf
Copy link
Copy Markdown
Collaborator

@igoramf igoramf commented May 22, 2026

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.

  • New Features
    • Trim to and prepend https:// if no scheme is present in the create handler.
    • Added a test to verify the normalized value is saved as https://....

Written for commit 3321246. Summary will update on new commits. Review in cubic

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread internal/api/handlers.go
http.Error(w, "'to' is required", http.StatusBadRequest)
return
}
if !strings.HasPrefix(to, "http://") && !strings.HasPrefix(to, "https://") {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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" {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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" {

@igoramf igoramf merged commit fda1a48 into main May 22, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant