Skip to content

Commit 9b86c3d

Browse files
authored
fix: resolve buffer not been cleared (#1590)
<!-- Important: Before developing new features, please open an issue to discuss your ideas with the maintainers. This ensures project alignment and helps avoid unnecessary work for you. Thank you for your contribution! Please provide a detailed description below and ensure you've met all the requirements. Squashed commit messages must follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) standard to facilitate changelog generation. Please ensure your PR title follows the Conventional Commits specification, using the appropriate type (e.g., feat, fix, docs) and scope. Examples of good PR titles: - 💥feat!: change implementation in an non-backward compatible way - ✨feat(auth): add support for OAuth2 login - 🐞fix(router): add support for custom metrics - 📚docs(README): update installation instructions - 🧹chore(deps): bump dependencies to latest versions --> This PR resolves the following issue, where the buffer does not seem to be cleared <img width="983" height="468" alt="image" src="https://github.com/user-attachments/assets/331e473e-75fd-41c3-8fa5-8b2a52b8501f" /> @coderabbitai summary ## Checklist - [ ] I have discussed my proposed changes in an issue and have received approval to proceed. - [ ] I have followed the coding standards of the project. - [ ] Tests or benchmarks have been added or updated. ## Open Source AI Manifesto This project follows the principles of the [Open Source AI Manifesto](https://human-oss.dev). Please ensure your contribution aligns with its principles. <!-- Please add any additional information or context regarding your changes here. -->
1 parent 804d7aa commit 9b86c3d

2 files changed

Lines changed: 43 additions & 3 deletions

File tree

v2/pkg/astnormalization/inline_arguments.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func (v *inlineArgumentsVisitor) EnterArgument(ref int) {
9797
}
9898

9999
finding := InlineArgument{
100-
ArgumentName: v.operation.ArgumentNameString(ref),
100+
ArgumentName: string(v.operation.ArgumentNameBytes(ref)),
101101
ValueKind: valueKind,
102102
Position: v.operation.Arguments[ref].Position,
103103
Path: v.Path.DotDelimitedString(),
@@ -107,9 +107,9 @@ func (v *inlineArgumentsVisitor) EnterArgument(ref int) {
107107
finding.AncestorKind = parent.Kind
108108
switch parent.Kind {
109109
case ast.NodeKindField:
110-
finding.AncestorName = v.operation.FieldNameString(parent.Ref)
110+
finding.AncestorName = string(v.operation.FieldNameBytes(parent.Ref))
111111
case ast.NodeKindDirective:
112-
finding.AncestorName = v.operation.DirectiveNameString(parent.Ref)
112+
finding.AncestorName = string(v.operation.DirectiveNameBytes(parent.Ref))
113113
}
114114

115115
v.result.InlineArguments = append(v.result.InlineArguments, finding)

v2/pkg/astnormalization/inline_arguments_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,46 @@ func TestInlineArgumentsRule_Enforce(t *testing.T) {
269269
})
270270
}
271271

272+
func TestInlineArgumentsRule_FindingOwnsItsBytes(t *testing.T) {
273+
definitionDocument := unsafeparser.ParseGraphqlDocumentString(inlineArgumentsTestSchema)
274+
require.NoError(t, asttransform.MergeDefinitionWithBaseSchema(&definitionDocument))
275+
276+
operationDocument := unsafeparser.ParseGraphqlDocumentString(`query GetField { field(obj: { a: 1 }) @include(if: true) }`)
277+
report := &operationreport.Report{}
278+
279+
normalizer := NewWithOpts(WithInlineArgumentsValidation(InlineArgumentsValidationOptions{Enforce: false}))
280+
result := normalizer.NormalizeNamedOperationWithResult(&operationDocument, &definitionDocument, nil, report, RunOptions{})
281+
282+
require.False(t, report.HasErrors())
283+
require.Len(t, result.InlineArguments, 2)
284+
285+
fieldArg := result.InlineArguments[0]
286+
require.Equal(t, "obj", fieldArg.ArgumentName)
287+
require.Equal(t, "field", fieldArg.AncestorName)
288+
require.Equal(t, ast.NodeKindField, fieldArg.AncestorKind)
289+
290+
directiveArg := result.InlineArguments[1]
291+
require.Equal(t, "if", directiveArg.ArgumentName)
292+
require.Equal(t, "include", directiveArg.AncestorName)
293+
require.Equal(t, ast.NodeKindDirective, directiveArg.AncestorKind)
294+
295+
// Simulate the operation document being recycled from the pool: scribble over
296+
// its input buffer. A finding that owns its bytes is unaffected; one that
297+
// aliases the input buffer is corrupted.
298+
for i := range operationDocument.Input.RawBytes {
299+
operationDocument.Input.RawBytes[i] = 'x'
300+
}
301+
302+
assert.Equal(t, "obj", result.InlineArguments[0].ArgumentName,
303+
"field ArgumentName must own its bytes, not alias the operation input buffer")
304+
assert.Equal(t, "field", result.InlineArguments[0].AncestorName,
305+
"field AncestorName must own its bytes, not alias the operation input buffer")
306+
assert.Equal(t, "if", result.InlineArguments[1].ArgumentName,
307+
"directive ArgumentName must own its bytes, not alias the operation input buffer")
308+
assert.Equal(t, "include", result.InlineArguments[1].AncestorName,
309+
"directive AncestorName must own its bytes, not alias the operation input buffer")
310+
}
311+
272312
func TestInlineArgumentsRule_OptionOffReturnsNil(t *testing.T) {
273313
definitionDocument := unsafeparser.ParseGraphqlDocumentString(inlineArgumentsTestSchema)
274314
require.NoError(t, asttransform.MergeDefinitionWithBaseSchema(&definitionDocument))

0 commit comments

Comments
 (0)