Skip to content

Commit

Permalink
Merge pull request #13419 from Snuffleupagus/more-stringToBytes
Browse files Browse the repository at this point in the history
Use the `stringToBytes` helper function in more places
  • Loading branch information
timvandermeij committed May 22, 2021
2 parents b2ffebe + 53a7024 commit 92e7310
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
6 changes: 2 additions & 4 deletions src/core/xfa/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import {
getRelevant,
getStringOption,
} from "./utils.js";
import { Util, warn } from "../../shared/util.js";
import { stringToBytes, Util, warn } from "../../shared/util.js";

const TEMPLATE_NS_ID = NamespaceIds.template.id;

Expand Down Expand Up @@ -2262,9 +2262,7 @@ class Image extends StringObject {
}

if (this.transferEncoding === "base64") {
const buffer = Uint8Array.from(atob(this[$content]), c =>
c.charCodeAt(0)
);
const buffer = stringToBytes(atob(this[$content]));
const blob = new Blob([buffer], { type: this.contentType });
html.attributes.src = URL.createObjectURL(blob);
return html;
Expand Down
8 changes: 4 additions & 4 deletions src/display/content_disposition.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* limitations under the License.
*/

import { stringToBytes } from "../shared/util.js";

// This getFilenameFromContentDispositionHeader function is adapted from
// https://github.com/Rob--W/open-in-browser/blob/7e2e35a38b8b4e981b11da7b2f01df0149049e92/extension/content-disposition.js
// with the following changes:
Expand Down Expand Up @@ -85,10 +87,8 @@ function getFilenameFromContentDispositionHeader(contentDisposition) {
}
try {
const decoder = new TextDecoder(encoding, { fatal: true });
const bytes = Array.from(value, function (ch) {
return ch.charCodeAt(0) & 0xff;
});
value = decoder.decode(new Uint8Array(bytes));
const buffer = stringToBytes(value);
value = decoder.decode(buffer);
needsEncodingFixup = false;
} catch (e) {
// TextDecoder constructor threw - unrecognized encoding.
Expand Down

0 comments on commit 92e7310

Please sign in to comment.