-
Notifications
You must be signed in to change notification settings - Fork 2k
fix: Support @contentType for multiline values #6217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix: Support @contentType for multiline values #6217
Conversation
|
The linter is failing on files that I didn’t modify in this PR, even though Could you confirm if the CI environment uses a different linter configuration or Node version? Should I fix those unrelated files? |
Fixes the issue where the @ContentType annotation broke the parsing of multiline values.
7fe9060 to
d918696
Compare
WalkthroughAdds support for an inline content-type annotation Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
|
Alright, rebasing onto the latest |
Not strictly needed since body:file uses single-line values in practice, but doesn't hurt and matches what multipartExtractContentType does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
packages/bruno-lang/v2/src/bruToJson.js (2)
55-57: Multiline'''blocks with@contentTypelook correct; consider improving indentation handling and trimmingThe grammar + semantics for
multilinetextblockandsinglelinevalueline up well with the multipart@contentType(...)pipeline and fix the original bug: multiline values now carry the annotation through tomultipartExtractContentType.Two optional refinements you might consider:
- Instead of hard‑coding
line.slice(4)inmultilinetextblock, reuseoutdentStringor aminIndentstyle approach (as inparseExampleContent) to avoid stripping real content if indentation is not exactly 4 spaces or includes tabs.- Since
pair()already doesvalue.ast.trim(),singlelinevaluecould just returnchars.sourceString || ''and let the trim happen in one place, unless you explicitly want trimming at this layer too.Also applies to: 69-71, 422-435
214-229: Unify@contentTyperegex and align trimming behavior between multipart and fileBoth
multipartExtractContentTypeandfileExtractContentTypenow use the same pattern/^(.*?)\s*@contentType\((.*?)\)\s*$/s, which is good. Right now though:
- The regex literal is duplicated in two places.
fileExtractContentTypetrims bothmatch[1]andmatch[2], whilemultipartExtractContentTypeleaves them as‑is, which can lead to subtle differences if someone writes extra spaces inside the annotation.To keep behavior consistent and easier to maintain, you could:
- Factor the regex into a shared constant (e.g.
CONTENT_TYPE_ANNOTATION_RE) and reuse it in both helpers.- Decide whether you always want to normalize
contentType(and possibly value) with.trim()in both helpers, or keep raw spacing intentionally — and implement that choice uniformly.
Description
Fixes #5767, where the
@contentTypeannotation caused parsing issues for multiline values.I updated the existing
multilinetextblockrule so it can optionally parse a trailing@contentTypeannotation. This annotation is appended to the end of the value and later extracted bymultipartExtractContentType.An alternative would be to add a dedicated dictionary-like grammar element specifically for
body:multipart-form, since@contentTypewith multiline values only makes sense there. However, that approach would require a larger grammar and semantic change.Contribution Checklist:
Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.
Publishing to New Package Managers
Please see here for more information.
Summary by CodeRabbit
New Features
Tests
✏️ Tip: You can customize this high-level summary in your review settings.