diff --git a/lib/tdf3/src/utils/unwrap.ts b/lib/tdf3/src/utils/unwrap.ts
index 36be954f2..a6e442549 100644
--- a/lib/tdf3/src/utils/unwrap.ts
+++ b/lib/tdf3/src/utils/unwrap.ts
@@ -3,7 +3,8 @@ import { InvalidFileError } from '../../../src/errors.js';
export function unwrapHtml(htmlPayload: Uint8Array): Uint8Array {
const html = new TextDecoder().decode(htmlPayload);
- const payloadRe = /]*?value=['"]?([a-zA-Z0-9+/=]+)['"]?/;
+ const payloadRe =
+ /]*id=(?:['"]?)data-input(?:['"]?)[^>]*value=(?:['"]?)([a-zA-Z0-9+/=\-_]+)(?:['"]?)/;
const reResult = payloadRe.exec(html);
if (!reResult) {
throw new InvalidFileError('Payload is missing');
diff --git a/lib/tests/mocha/unit/unwrap.spec.ts b/lib/tests/mocha/unit/unwrap.spec.ts
index ce49eb65e..5c1d84ebb 100644
--- a/lib/tests/mocha/unit/unwrap.spec.ts
+++ b/lib/tests/mocha/unit/unwrap.spec.ts
@@ -25,4 +25,46 @@ describe('unwrapHtml', () => {
'There was a problem extracting the TDF3 payload'
);
});
+
+ describe('regex pattern variations', () => {
+ it('should handle double quotes', () => {
+ const htmlPayload = new TextEncoder().encode(
+ ''
+ );
+ const result = unwrapHtml(htmlPayload);
+ expect(new TextDecoder().decode(result)).to.equal('Hello World');
+ });
+
+ it('should handle single quotes', () => {
+ const htmlPayload = new TextEncoder().encode(
+ ""
+ );
+ const result = unwrapHtml(htmlPayload);
+ expect(new TextDecoder().decode(result)).to.equal('Hello World');
+ });
+
+ it('should handle no quotes', () => {
+ const htmlPayload = new TextEncoder().encode(
+ ''
+ );
+ const result = unwrapHtml(htmlPayload);
+ expect(new TextDecoder().decode(result)).to.equal('Hello World');
+ });
+
+ it('should handle URL-safe base64 characters', () => {
+ const htmlPayload = new TextEncoder().encode(
+ ''
+ );
+ const result = unwrapHtml(htmlPayload);
+ expect(new TextDecoder().decode(result)).to.equal('Hello-World?');
+ });
+
+ it('should handle additional attributes', () => {
+ const htmlPayload = new TextEncoder().encode(
+ ''
+ );
+ const result = unwrapHtml(htmlPayload);
+ expect(new TextDecoder().decode(result)).to.equal('Hello World');
+ });
+ });
});