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(md5-js): call fromUtf8 from correct environment #2641

Merged
merged 1 commit into from
Aug 5, 2021

Conversation

trivikr
Copy link
Member

@trivikr trivikr commented Aug 5, 2021

Issue

Fixes: #2640

Description

Calls fromUtf8 from correct environment in md5-js

Testing

Added console.log as follows:

packages/util-utf8-browser/src/index.ts
 declare const TextDecoder: Function | undefined;
 declare const TextEncoder: Function | undefined;
 
-export const fromUtf8 = (input: string): Uint8Array =>
-  typeof TextEncoder === "function" ? textEncoderFromUtf8(input) : jsFromUtf8(input);
+export const fromUtf8 = (input: string): Uint8Array => {
+  console.log("util-utf8-browser");
+  return typeof TextEncoder === "function" ? textEncoderFromUtf8(input) : jsFromUtf8(input);
+};
 
 export const toUtf8 = (input: Uint8Array): string =>
   typeof TextDecoder === "function" ? textEncoderToUtf8(input) : jsToUtf8(input);
packages/util-utf8-node/src/index.ts
 import { fromArrayBuffer, fromString } from "@aws-sdk/util-buffer-from";
 
 export const fromUtf8 = (input: string): Uint8Array => {
+  console.log("util-utf8-node");
   const buf = fromString(input, "utf8");
   return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength / Uint8Array.BYTES_PER_ELEMENT);
 };

Test code

// test.js
import { Md5 } from "../aws-sdk-js-v3/packages/md5-js/dist/cjs/index.js";

const hash = new Md5();
hash.update("test");
console.log(btoa(String.fromCharCode.apply(null, await hash.digest())));

Node.js

$ node test.js
util-utf8-node
CY9rzUYh03PK3k6DJie09g==

Browser

Created bundle using webpack

$ webpack --version
webpack 5.48.0
webpack-cli 4.7.2

$ webpack ./test.js

Copied code from dist/main.js and pasted it in browser.
Verified that the following was printed in console:

util-utf8-browser
CY9rzUYh03PK3k6DJie09g==

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

@codecov-commenter
Copy link

Codecov Report

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

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2641   +/-   ##
=======================================
  Coverage        ?   60.64%           
=======================================
  Files           ?      515           
  Lines           ?    27672           
  Branches        ?     6797           
=======================================
  Hits            ?    16783           
  Misses          ?    10889           
  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 f01142c...a4598bc. Read the comment docs.

@aws-sdk-js-automation
Copy link

AWS CodeBuild CI Report

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

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

@trivikr trivikr merged commit affa927 into aws:main Aug 5, 2021
@trivikr trivikr deleted the md5-util-utf8-fix branch August 5, 2021 19: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 20, 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.

The @aws-sdk/md5-js calls fromUtf8 from browser environment in Node.js
4 participants