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

fix(fast-xml-parser): populate contents from '#text' if available #993

Merged
merged 4 commits into from
Mar 11, 2020

Conversation

trivikr
Copy link
Member

@trivikr trivikr commented Mar 10, 2020

Issue #, if available:
Option 2 for fixing #987

Description of changes:

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

@aws-sdk-js-automation
Copy link

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@trivikr

This comment has been minimized.

@codecov-io

This comment has been minimized.

@aws-sdk-js-automation

This comment has been minimized.

@trivikr trivikr force-pushed the s3-bucketLocation-parser-fix branch from a4948d0 to 55e686e Compare March 11, 2020 18:47
@trivikr
Copy link
Member Author

trivikr commented Mar 11, 2020

The update was verified by using modified version of code in https://github.com/trivikr/xml-parser-comparison:

Code:

const fastXmlParser = require("fast-xml-parser");
const { readFileSync } = require("fs");

const xmlData = readFileSync("example.xml").toString();
const parsedObj = fastXmlParser.parse(xmlData, {
  attributeNamePrefix: "",
  ignoreAttributes: false
});
const textNodeName = "#text";
const key = Object.keys(parsedObj)[0];
const parsedObjToReturn = parsedObj[key];
if (parsedObjToReturn[textNodeName]) {
  parsedObjToReturn[key] = parsedObjToReturn[textNodeName];
  delete parsedObjToReturn[textNodeName];
}
console.log(JSON.stringify(parsedObjToReturn, null, 2));

When example.xml contains:

<?xml version="1.0"?>
<AccessControlPolicy
	xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
	<Owner>
		<DisplayName>trivikr</DisplayName>
	</Owner>
</AccessControlPolicy>

Output is:

{
  "xmlns": "http://s3.amazonaws.com/doc/2006-03-01/",
  "Owner": {
    "DisplayName": "trivikr"
  }
}

When example.xml contains:

<?xml version="1.0"?>
<LocationConstraint xmlns="http://s3.amazonaws.com/doc/2006-03-01/">EU</LocationConstraint>

Output is:

{
  "xmlns": "http://s3.amazonaws.com/doc/2006-03-01/",
  "LocationConstraint": "EU"
}

@aws-sdk-js-automation
Copy link

AWS CodeBuild CI Report

  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@trivikr trivikr merged commit 87af396 into aws:smithy-codegen Mar 11, 2020
@trivikr trivikr deleted the s3-bucketLocation-parser-fix branch March 11, 2020 21:18
AllanZhengYP pushed a commit to AllanZhengYP/aws-sdk-js-v3 that referenced this pull request Mar 20, 2020
trivikr added a commit to trivikr/aws-sdk-js-v3 that referenced this pull request Mar 20, 2020
@lock
Copy link

lock bot commented Mar 21, 2020

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.

@lock lock bot locked as resolved and limited conversation to collaborators Mar 21, 2020
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