hx-ext-amz-content-sha256 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/main.js +5 -2
- package/min.js +1 -1
- package/package.json +1 -1
package/main.js
CHANGED
|
@@ -45,9 +45,12 @@ htmx.defineExtension("amz-content-sha256", {
|
|
|
45
45
|
|
|
46
46
|
// Ensure the target is a valid HTMLFormElement
|
|
47
47
|
if (form instanceof HTMLFormElement) {
|
|
48
|
-
// Create a FormData object from the form, and
|
|
48
|
+
// Create a FormData object from the form, and serialize using encodeURIComponent
|
|
49
|
+
// to match HTMX's internal encoding (URLSearchParams encodes differently)
|
|
49
50
|
const formData = new FormData(form);
|
|
50
|
-
const data =
|
|
51
|
+
const data = Array.from(formData.entries())
|
|
52
|
+
.map(([k, v]) => encodeURIComponent(k) + '=' + encodeURIComponent(v))
|
|
53
|
+
.join('&');
|
|
51
54
|
|
|
52
55
|
// Calculate the SHA-256 hash of the form data
|
|
53
56
|
const sha256Hash = await this.calculateSHA256(data);
|
package/min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
htmx.defineExtension("amz-content-sha256",{init:function(){return this.RequestHashQueue={},this.calculateSHA256=async e=>{const t=(new TextEncoder).encode(e),a=await crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(a)).map((e=>e.toString(16).padStart(2,"0"))).join("")},null},onEvent:async function(e,t){switch(e){case"htmx:confirm":if("post"==t.detail.verb||"put"==t.detail.verb){t.preventDefault();const e=t.target;if(e instanceof HTMLFormElement){const a=new FormData(e),s=
|
|
1
|
+
htmx.defineExtension("amz-content-sha256",{init:function(){return this.RequestHashQueue={},this.calculateSHA256=async e=>{const t=(new TextEncoder).encode(e),a=await crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(a)).map((e=>e.toString(16).padStart(2,"0"))).join("")},null},onEvent:async function(e,t){switch(e){case"htmx:confirm":if("post"==t.detail.verb||"put"==t.detail.verb){t.preventDefault();const e=t.target;if(e instanceof HTMLFormElement){const a=new FormData(e),s=Array.from(a.entries()).map((([e,t])=>encodeURIComponent(e)+"="+encodeURIComponent(t))).join("&"),i=await this.calculateSHA256(s);this.RequestHashQueue[t.detail.path]?this.RequestHashQueue[t.detail.path].push(i):this.RequestHashQueue[t.detail.path]=[i]}t.detail.issueRequest()}break;case"htmx:configRequest":"post"!=t.detail.verb&&"put"!=t.detail.verb||this.RequestHashQueue[t.detail.path].length>0&&(t.detail.headers["x-amz-content-sha256"]=this.RequestHashQueue[t.detail.path].pop())}}});
|