Skip to content

fix(clients): only trim xml tag values which contain newline #2653

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

Merged
merged 9 commits into from
Aug 13, 2021

Conversation

trivikr
Copy link
Member

@trivikr trivikr commented Aug 9, 2021

Issue

Internal JS-2756

Description

Do not trim values while parsing XML

Testing

Protocol tests

Additional context

Follow-up to #2646


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@trivikr
Copy link
Member Author

trivikr commented Aug 10, 2021

Debugged with a specific test case Ec2InvalidGreetingError:Error:GreetingWithErrors

Ec2InvalidGreetingError:Error:GreetingWithErrors

    Failed: "Expected a InvalidGreeting to be thrown, got TypeError instead"

      368 |     if (err.name !== "InvalidGreeting") {
      369 |       console.log(err);
    > 370 |       fail(`Expected a InvalidGreeting to be thrown, got ${err.name} instead`);
          |       ^
      371 |       return;
      372 |     }
      373 |     const r: any = err;

      at Env.fail (../../node_modules/jest-jasmine2/build/jasmine/Env.js:722:61)
      at Object.<anonymous>.it (tests/functional/ec2query.spec.ts:370:7)

The parsedObj from xmlParse operation:

  • When trimming is enabled:
{
  "Response": {
    "Errors": {
      "Error": {
        "Code": "InvalidGreeting",
        "Message": "Hi"
      }
    },
    "RequestId": "foo-id"
  }
}
  • When trimming is removed:
{
  "Response": {
    "#text": "\n          \n          \n      ",
    "Errors": {
      "#text": "\n              \n          ",
      "Error": {
        "#text": "\n                  \n                  \n              ",
        "Code": "InvalidGreeting",
        "Message": "Hi"
      }
    },
    "RequestId": "foo-id"
  }
}

@trivikr
Copy link
Member Author

trivikr commented Aug 10, 2021

PR which introduced logic to read contents from #text to fix a bug with LocationConstraint #993

@trivikr
Copy link
Member Author

trivikr commented Aug 10, 2021

Requirement: Preserve whitespace values only if they are inside a tag, and not if they appear prior to child tag.

For example, the XML value being returned in protocol_test is:

<?xml version = "1.0" encoding = "UTF-8"?>
  <SimpleScalarPropertiesInputOutput>
      <stringValue>  </stringValue>
  </SimpleScalarPropertiesInputOutput>

When trimming is disabled, the parsed output is:

{
  "SimpleScalarPropertiesInputOutput": { "#text": "\n          \n      ", "stringValue": "  " }
}

When trimming is enabled, the parsed output is:

{ "SimpleScalarPropertiesInputOutput": { "stringValue": "" } }

The output we want:

{ "SimpleScalarPropertiesInputOutput": { "stringValue": "  " } }

@codecov-commenter
Copy link

codecov-commenter commented Aug 10, 2021

Codecov Report

❗ No coverage uploaded for pull request base (main@398a092). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2653   +/-   ##
=======================================
  Coverage        ?   60.64%           
=======================================
  Files           ?      516           
  Lines           ?    27774           
  Branches        ?     6825           
=======================================
  Hits            ?    16844           
  Misses          ?    10930           
  Partials        ?        0           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 398a092...6391232. Read the comment docs.

@trivikr trivikr changed the title fix(codegen): do not trim values while parsing XML fix(clients): only trim xml tag values which contain newline Aug 10, 2021
@trivikr trivikr force-pushed the xml-parser-disable-trim-values branch from 772be46 to 95e0e4c Compare August 10, 2021 17:33
@trivikr trivikr requested a review from AllanZhengYP August 10, 2021 18:27
@aws-sdk-js-automation
Copy link

AWS CodeBuild CI Report

  • CodeBuild project: sdk-staging-test
  • Commit ID: 6391232
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@AllanZhengYP
Copy link
Contributor

This is approved because the condition of triming the value is stricter than before. But we do need to confirm weather this is a valid test case, should remove the value node from wire response?

@trivikr trivikr merged commit 28336f5 into aws:main Aug 13, 2021
@trivikr trivikr deleted the xml-parser-disable-trim-values branch August 13, 2021 18:04
@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants