Skip to content
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

ParseNode Failure while processing string literal #30

Closed
dadams39 opened this issue Jun 23, 2022 · 11 comments · Fixed by #34
Closed

ParseNode Failure while processing string literal #30

dadams39 opened this issue Jun 23, 2022 · 11 comments · Fixed by #34
Assignees
Labels
bug Something isn't working

Comments

@dadams39
Copy link
Contributor

Present on github.com/microsoft/kiota-serialization-json-go v0.5.1 & v0.5.2
Related to: #26

call: js.NewJsonParseNodeFactory().GetRootParseNode("application/json", bytes)
where

bytes

{"id":"AAMkADhlNjU5MzMzLTUyYzItNDJmYi04ZTgzLTkzYTE1ZDg0OTRjOQBGAAAAAAC9muvJZ4uvRYeQkyPxt40qBwCDUn-uvuceTb3Zb9F345Q1AAAAAAEMAACDUn-uvuceTb3Zb9F345Q1AAAuZPpRAAA=","@odata.context":"https://graph.microsoft.com/v1.0/$metadata#users('67fc108d-cc22-4a54-96af-7b91c5d34cf2')/messages/$entity","@odata.etag":"W/\"CQAAABYAAACDUn/uvuceTb3Zb9F345Q1AAAuT0ok\"","categories":[],"changeKey":"CQAAABYAAACDUn/uvuceTb3Zb9F345Q1AAAuT0ok","createdDateTime":"2022-06-15T05:27:05Z","lastModifiedDateTime":"2022-06-15T05:27:07Z","bccRecipients":[],"body":{"content":"<html lang=\"en\" style=\"min-height:100%; background:#ffffff\"><head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"><meta name=\"viewport\" content=\"width=device-width\"><meta name=\"eventId\" content=\"aad-identity-protection-weekly-digest-report-v2\"><meta name=\"messageId\" content=\"d4db577e-fe10-4bea-8e6d-164bb1ebb039\"><meta name=\"cloud\" content=\"AZ\"><style id=\"mediaqueries\">
<!--
@media only screen and (max-width: 640px) {
.wrap-dangler
	{padding-right:10%!important}
.wrap-dangler.small-text-center .wrap-dangler.text-center

Receiving error: invalid character '\r' in string literal

@dadams39 dadams39 changed the title ParseNode Failure w/ string literal ParseNode Failure while processing string literal Jun 23, 2022
@dadams39
Copy link
Contributor Author

Error Tracking

json_parse_node.go
During func loadJsonTree(decoder *json.Decoder) (*JsonParseNode, error)
line 54:

childNode, err := loadJsonTree(decoder)

context: keyStr: "body

encoding/json.SyntaxError {msg: "invalid character '\\r' in string literal", Offset: 592}

@dadams39
Copy link
Contributor Author

Traced further back to libexec/src/encoding/json/stream.go which we will not be able to change.
Verified in JsonLint

Error: Parse error on line 11:
...dy": {		"content": "<html lang=\"en\" s
----------------------^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'undefined'

Json was produced by Serialization Writer.

@baywet
Copy link
Member

baywet commented Jun 27, 2022

Hi @dadams39,
Thank you for reporting this.
Would you be willing to submit a PR to address this and microsoftgraph/msgraph-sdk-go#203 (\ needs to be replaced first before anything else) ?

@dadams39
Copy link
Contributor Author

From what I can tell, the Serialization Writer creates these types of messages incorrectly. I'm unable to verify the original data store input. The ParseNode failing to write what is an invalid JSON object is the correct outcome. Going to need to find a test case that I can reference with the Graph Explorer to be able to find a good example to fix the parsing error.

@baywet
Copy link
Member

baywet commented Jun 28, 2022

hopefully the lengthy explanation I've added in #28 clarifies the situation.
I do believe we should still escape \t in the serialization writer.

@dadams39
Copy link
Contributor Author

dadams39 commented Jul 6, 2022

Returning to this as the following has been closed: microsoftgraph/msgraph-sdk-go#203. The error remains unchanged.

@baywet
Copy link
Member

baywet commented Jul 6, 2022

Thanks for the follow up, so \t in a string value still breaks things, correct?

@baywet
Copy link
Member

baywet commented Jul 7, 2022

ah, I can see you left a thumbs up. This doesn't send out a notification to catch my attention back. Thanks for confirming.
Is this something you'd be willing to submit a pull request for?

func TestEscapesNewLinesInStrings(t *testing.T) {

@dadams39
Copy link
Contributor Author

dadams39 commented Jul 7, 2022

The tab is showing up as the issue, but the true failure may be the \r carriage return. I am working to see the target file if I can create a valid JSON making these changes. I will be submitting the PR relatively soon.

@baywet
Copy link
Member

baywet commented Jul 7, 2022

Since we're already escaping n it'd make sense to escape both t and r indeed

@dadams39
Copy link
Contributor Author

Can be closed after PR #34 is merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants