Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@rorydbain
Copy link
Contributor

@rorydbain rorydbain commented Jul 21, 2025

Summary

  • Fixed panic in generated query parameter parsing code when malformed brackets are provided
  • Added validation to check that brackets are properly paired and ordered before attempting string slicing
  • Updated test expectations to match the new error handling

Problem

When query parameters with malformed brackets are sent (e.g., custom_field[id]]][operator] or custom_field[[nestedbrackets]]), the generated code would panic with runtime error: slice bounds out of range [2:0].

This occurred because the code only checked if the closing bracket was missing (closeIdx == -1) but didn't validate:

  1. If the opening bracket exists (openIdx == -1)
  2. If the closing bracket comes after the opening bracket (closeIdx <= openIdx)

Solution

Updated the template to check all three conditions:

if openIdx == -1 || closeIdx == -1 || closeIdx <= openIdx {
    err = goa.MergeErrors(err, goa.DecodePayloadError("invalid query string: malformed brackets"))
}

@raphael
Copy link
Member

raphael commented Jul 25, 2025

That makes sense, thank you for the great contribution!

@raphael raphael merged commit e6943a5 into goadesign:v3 Jul 25, 2025
9 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.

2 participants