Merge pull request #13419 from Snuffleupagus/more-stringToBytes
Use the `stringToBytes` helper function in more places
This commit is contained in:
		
						commit
						92e731011d
					
				| @ -57,7 +57,7 @@ import { | |||||||
|   getRelevant, |   getRelevant, | ||||||
|   getStringOption, |   getStringOption, | ||||||
| } from "./utils.js"; | } 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; | const TEMPLATE_NS_ID = NamespaceIds.template.id; | ||||||
| 
 | 
 | ||||||
| @ -2262,9 +2262,7 @@ class Image extends StringObject { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     if (this.transferEncoding === "base64") { |     if (this.transferEncoding === "base64") { | ||||||
|       const buffer = Uint8Array.from(atob(this[$content]), c => |       const buffer = stringToBytes(atob(this[$content])); | ||||||
|         c.charCodeAt(0) |  | ||||||
|       ); |  | ||||||
|       const blob = new Blob([buffer], { type: this.contentType }); |       const blob = new Blob([buffer], { type: this.contentType }); | ||||||
|       html.attributes.src = URL.createObjectURL(blob); |       html.attributes.src = URL.createObjectURL(blob); | ||||||
|       return html; |       return html; | ||||||
|  | |||||||
| @ -13,6 +13,8 @@ | |||||||
|  * limitations under the License. |  * limitations under the License. | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
|  | import { stringToBytes } from "../shared/util.js"; | ||||||
|  | 
 | ||||||
| // This getFilenameFromContentDispositionHeader function is adapted from
 | // This getFilenameFromContentDispositionHeader function is adapted from
 | ||||||
| // https://github.com/Rob--W/open-in-browser/blob/7e2e35a38b8b4e981b11da7b2f01df0149049e92/extension/content-disposition.js
 | // https://github.com/Rob--W/open-in-browser/blob/7e2e35a38b8b4e981b11da7b2f01df0149049e92/extension/content-disposition.js
 | ||||||
| // with the following changes:
 | // with the following changes:
 | ||||||
| @ -85,10 +87,8 @@ function getFilenameFromContentDispositionHeader(contentDisposition) { | |||||||
|       } |       } | ||||||
|       try { |       try { | ||||||
|         const decoder = new TextDecoder(encoding, { fatal: true }); |         const decoder = new TextDecoder(encoding, { fatal: true }); | ||||||
|         const bytes = Array.from(value, function (ch) { |         const buffer = stringToBytes(value); | ||||||
|           return ch.charCodeAt(0) & 0xff; |         value = decoder.decode(buffer); | ||||||
|         }); |  | ||||||
|         value = decoder.decode(new Uint8Array(bytes)); |  | ||||||
|         needsEncodingFixup = false; |         needsEncodingFixup = false; | ||||||
|       } catch (e) { |       } catch (e) { | ||||||
|         // TextDecoder constructor threw - unrecognized encoding.
 |         // TextDecoder constructor threw - unrecognized encoding.
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user