Skip to content

Conversation

@google-labs-jules
Copy link
Contributor

Fixes an issue where strings containing newline characters were not correctly escaped when performing insert or update operations in DataConnect, causing "Unexpected " errors.

The fix replaces a custom string escaping implementation that only handled backslashes and double quotes with JSON.stringify, which correctly handles all JSON-compatible escape sequences including \n, \r, and \t.

Added a regression test to test/unit/data-connect/data-connect-api-client-internal.spec.ts.


PR created automatically by Jules for task 9056897190574707316 started by @yuchenshi

Replaces manual string escaping with JSON.stringify in DataConnect API client to properly handle newlines and other control characters in mutation arguments.
Adds a regression test for verifying newline escaping.

Fixes #3043
@google-labs-jules
Copy link
Contributor Author

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

});
});

// --- Issue #3043 ---
Copy link
Member

Choose a reason for hiding this comment

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

Remove this line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed.

// which means the string "Line 1\\nLine 2" should be present in the call args.
expect(callArgs).to.include('content: "Line 1\\nLine 2"');
});
});
Copy link
Member

Choose a reason for hiding this comment

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

Please add more tests, one featuring backslash, one with double quotes, one with the tab charater, and one with an emoji

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added tests for backslash, double quotes, tab character, and emoji.

const data = {
content: 'Line 1\nLine 2',
};
// JSON.stringify("Line 1\nLine 2") -> "Line 1\nLine 2"
Copy link
Member

Choose a reason for hiding this comment

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

Remove this line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed.

- Removed specified lines.
- Added tests for backslash, double quotes, tab character, and emoji string serialization.
@yuchenshi
Copy link
Member

@stephenarosaj Please verify my work using Jules and review as if I wrote the code. Don't worry about talking to Jules -- Jules won't respond to you, only me. ("instructions from the user who triggered this task")

Copy link
Contributor

@stephenarosaj stephenarosaj left a comment

Choose a reason for hiding this comment

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

LGTM - just requesting a few nits and one change in the tests

});
});

describe('Issue #3043: String serialization', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: probably remove the mention of issue #3043 in the describe string

});
});

describe('Issue #3043: String serialization', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

another nit: the comments above check expects are mostly unnecessary. the code itself describes what the comments say in plain language


it('should correctly escape double quotes', async () => {
const data = {
content: 'Quote "test"',
Copy link
Contributor

Choose a reason for hiding this comment

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

content doesn't match what's described in the comments down below. based on my understanding, i believe the expected behavior should be:

  • 'Quote "test"' --> 'Quote \"test\"'
  • 'Quote \"test\"' --> 'Quote \\"test\\"'

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