From 5eab9ac61446c50456e17d93a860698ebbd5e902 Mon Sep 17 00:00:00 2001 From: Anna-Lena Lumpp Date: Wed, 9 Aug 2023 12:21:42 +0200 Subject: [PATCH 1/6] accepts newlines in dataURL + 2 new tests --- src/nodes/image.ts | 4 ++-- test/common/tests.js | 2 ++ test/specs/test-AL-arrows/spec.svg | 27 +++++++++++++++++++++++++++ test/specs/test-AL-picture/spec.svg | 12 ++++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 test/specs/test-AL-arrows/spec.svg create mode 100644 test/specs/test-AL-picture/spec.svg diff --git a/src/nodes/image.ts b/src/nodes/image.ts index 0762e77e..689246d0 100644 --- a/src/nodes/image.ts +++ b/src/nodes/image.ts @@ -10,8 +10,7 @@ import { Matrix } from 'jspdf' import { Viewport } from '../context/viewport' // groups: 1: mime-type (+ charset), 2: mime-type (w/o charset), 3: charset, 4: base64?, 5: body -export const dataUriRegex = /^\s*data:(([^/,;]+\/[^/,;]+)(?:;([^,;=]+=[^,;=]+))?)?(?:;(base64))?,(.*\s*)$/i - +export const dataUriRegex = /^\s*data:(([^/,;]+\/[^/,;]+)(?:;([^,;=]+=[^,;=]+))?)?(?:;(base64))?,((.|\s)*)$/i export class ImageNode extends GraphicsNode { private readonly imageLoadingPromise: Promise<{ data: string; format: string }> | null = null private readonly imageUrl: string | null @@ -118,6 +117,7 @@ export class ImageNode extends GraphicsNode { format = mimeTypeParts[1] data = match[5] + data = data.replace(/\s/g, '') if (match[4] === 'base64') { data = atob(data) } else { diff --git a/test/common/tests.js b/test/common/tests.js index d505b8b1..94f448fd 100644 --- a/test/common/tests.js +++ b/test/common/tests.js @@ -55,6 +55,8 @@ window.tests = [ 'svg-viewbox', 'svg-use', 'symbols', + 'test-AL-picture', + 'test-AL-arrows', 'text-fill-stroke', 'text-placement', 'title-element', diff --git a/test/specs/test-AL-arrows/spec.svg b/test/specs/test-AL-arrows/spec.svg new file mode 100644 index 00000000..abe9eaa4 --- /dev/null +++ b/test/specs/test-AL-arrows/spec.svg @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + diff --git a/test/specs/test-AL-picture/spec.svg b/test/specs/test-AL-picture/spec.svg new file mode 100644 index 00000000..3328c357 --- /dev/null +++ b/test/specs/test-AL-picture/spec.svg @@ -0,0 +1,12 @@ + + + + + From 95bfe53fd7c0a061a347327d7d31c3ec036a1944 Mon Sep 17 00:00:00 2001 From: Anna-Lena Lumpp Date: Wed, 9 Aug 2023 14:27:41 +0200 Subject: [PATCH 2/6] fixed requested changes --- src/nodes/image.ts | 4 +-- test/common/tests.js | 3 +-- .../image-data-urls-base64-spaces/spec.svg | 10 +++++++ test/specs/test-AL-arrows/spec.svg | 27 ------------------- 4 files changed, 13 insertions(+), 31 deletions(-) create mode 100644 test/specs/image-data-urls-base64-spaces/spec.svg delete mode 100644 test/specs/test-AL-arrows/spec.svg diff --git a/src/nodes/image.ts b/src/nodes/image.ts index 689246d0..c4e69847 100644 --- a/src/nodes/image.ts +++ b/src/nodes/image.ts @@ -10,7 +10,7 @@ import { Matrix } from 'jspdf' import { Viewport } from '../context/viewport' // groups: 1: mime-type (+ charset), 2: mime-type (w/o charset), 3: charset, 4: base64?, 5: body -export const dataUriRegex = /^\s*data:(([^/,;]+\/[^/,;]+)(?:;([^,;=]+=[^,;=]+))?)?(?:;(base64))?,((.|\s)*)$/i +export const dataUriRegex = /^\s*data:(([^/,;]+\/[^/,;]+)(?:;([^,;=]+=[^,;=]+))?)?(?:;(base64))?,(?:(.|\s)*)$/i export class ImageNode extends GraphicsNode { private readonly imageLoadingPromise: Promise<{ data: string; format: string }> | null = null private readonly imageUrl: string | null @@ -117,8 +117,8 @@ export class ImageNode extends GraphicsNode { format = mimeTypeParts[1] data = match[5] - data = data.replace(/\s/g, '') if (match[4] === 'base64') { + data = data.replace(/\s/g, '') data = atob(data) } else { data = decodeURIComponent(data) diff --git a/test/common/tests.js b/test/common/tests.js index 94f448fd..bba5c6e0 100644 --- a/test/common/tests.js +++ b/test/common/tests.js @@ -31,6 +31,7 @@ window.tests = [ 'gradient-units', 'gradients-and-patterns-mixed', 'hidden-clippath', + 'image-data-urls-base64-spaces', 'image-svg-urls', 'line-default-coordinates', 'markers', @@ -55,8 +56,6 @@ window.tests = [ 'svg-viewbox', 'svg-use', 'symbols', - 'test-AL-picture', - 'test-AL-arrows', 'text-fill-stroke', 'text-placement', 'title-element', diff --git a/test/specs/image-data-urls-base64-spaces/spec.svg b/test/specs/image-data-urls-base64-spaces/spec.svg new file mode 100644 index 00000000..7bec8cd8 --- /dev/null +++ b/test/specs/image-data-urls-base64-spaces/spec.svg @@ -0,0 +1,10 @@ + + + + + diff --git a/test/specs/test-AL-arrows/spec.svg b/test/specs/test-AL-arrows/spec.svg deleted file mode 100644 index abe9eaa4..00000000 --- a/test/specs/test-AL-arrows/spec.svg +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - From 084c98eaa61ae70e25329dd1c1981b7bc1e51c24 Mon Sep 17 00:00:00 2001 From: Anna-Lena Lumpp Date: Wed, 9 Aug 2023 14:33:15 +0200 Subject: [PATCH 3/6] delete folder --- test/specs/test-AL-picture/spec.svg | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 test/specs/test-AL-picture/spec.svg diff --git a/test/specs/test-AL-picture/spec.svg b/test/specs/test-AL-picture/spec.svg deleted file mode 100644 index 3328c357..00000000 --- a/test/specs/test-AL-picture/spec.svg +++ /dev/null @@ -1,12 +0,0 @@ - - - - - From 221b4822123cc60991faaca03cc00457acee652b Mon Sep 17 00:00:00 2001 From: Anna-Lena Lumpp Date: Wed, 9 Aug 2023 16:54:42 +0200 Subject: [PATCH 4/6] fixed newline bug --- src/nodes/image.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/nodes/image.ts b/src/nodes/image.ts index c4e69847..d2d215c2 100644 --- a/src/nodes/image.ts +++ b/src/nodes/image.ts @@ -10,7 +10,7 @@ import { Matrix } from 'jspdf' import { Viewport } from '../context/viewport' // groups: 1: mime-type (+ charset), 2: mime-type (w/o charset), 3: charset, 4: base64?, 5: body -export const dataUriRegex = /^\s*data:(([^/,;]+\/[^/,;]+)(?:;([^,;=]+=[^,;=]+))?)?(?:;(base64))?,(?:(.|\s)*)$/i +export const dataUriRegex = /^\s*data:(([^/,;]+\/[^/,;]+)(?:;([^,;=]+=[^,;=]+))?)?(?:;(base64))?,((?:(.|\s)*))$/i export class ImageNode extends GraphicsNode { private readonly imageLoadingPromise: Promise<{ data: string; format: string }> | null = null private readonly imageUrl: string | null @@ -86,7 +86,7 @@ export class ImageNode extends GraphicsNode { } catch (e) { typeof console === 'object' && console.warn && - console.warn(`Could not load image ${this.imageUrl}.\n${e}`) + console.warn(`Could not load image ${this.imageUrl}. \n${e}`) } } } @@ -117,8 +117,9 @@ export class ImageNode extends GraphicsNode { format = mimeTypeParts[1] data = match[5] + if (match[4] === 'base64') { - data = data.replace(/\s/g, '') + data = data.replace(/\s/g || /\n/g, '') data = atob(data) } else { data = decodeURIComponent(data) From d3d10db93754223182ce0e4ac68a9a011fc97548 Mon Sep 17 00:00:00 2001 From: Anna-Lena Lumpp Date: Thu, 10 Aug 2023 10:32:21 +0200 Subject: [PATCH 5/6] requested changes --- src/nodes/image.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nodes/image.ts b/src/nodes/image.ts index d2d215c2..5d6637f3 100644 --- a/src/nodes/image.ts +++ b/src/nodes/image.ts @@ -10,7 +10,7 @@ import { Matrix } from 'jspdf' import { Viewport } from '../context/viewport' // groups: 1: mime-type (+ charset), 2: mime-type (w/o charset), 3: charset, 4: base64?, 5: body -export const dataUriRegex = /^\s*data:(([^/,;]+\/[^/,;]+)(?:;([^,;=]+=[^,;=]+))?)?(?:;(base64))?,((?:(.|\s)*))$/i +export const dataUriRegex = /^\s*data:(([^/,;]+\/[^/,;]+)(?:;([^,;=]+=[^,;=]+))?)?(?:;(base64))?,((?:.|\s)*)$/i export class ImageNode extends GraphicsNode { private readonly imageLoadingPromise: Promise<{ data: string; format: string }> | null = null private readonly imageUrl: string | null @@ -119,7 +119,7 @@ export class ImageNode extends GraphicsNode { data = match[5] if (match[4] === 'base64') { - data = data.replace(/\s/g || /\n/g, '') + data = data.replace(/\s/g, '') data = atob(data) } else { data = decodeURIComponent(data) From 1d8b8cfe4a79f7b0fcc7bd1f1d1ff44be5684255 Mon Sep 17 00:00:00 2001 From: Anna-Lena Lumpp Date: Thu, 10 Aug 2023 11:34:24 +0200 Subject: [PATCH 6/6] added image-data-urls-base64-spaces reference --- .../image-data-urls-base64-spaces/reference.pdf | Bin 0 -> 3695 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/specs/image-data-urls-base64-spaces/reference.pdf diff --git a/test/specs/image-data-urls-base64-spaces/reference.pdf b/test/specs/image-data-urls-base64-spaces/reference.pdf new file mode 100644 index 0000000000000000000000000000000000000000..2aa04dd92d2d7e7f8fde0d88a2780ab9c13a4330 GIT binary patch literal 3695 zcmcIm;d0_O5We4fiv5%6-E@K_8-wXEnK|G{nBEN(GLud-_d^(kI0cK?;+piC`UHKM z_D!z4vP}$53fG2&vE|iDyZdRi`<;w>{Zmo%*vX%N{qZ;RfPzp zOA6U$8)qR=?25&xT{2bP@Sa)SO@t*E2p5ii*%#V&1{`{t{Z#tLu=Buj07$ulbjq9` zqge{qbPi*%0Imsm0w!PRZx*urjQR*Nb2>6rGy>;BExsrdg_1dw_0-sNq|+44`4ESC z7R7ULuA=yToJNI!IsGU}P4`wN;JJ7vGXHRWzht~|xbf4DUd&$KgXTAQFq|%;`!(k8 zYr_zHgA)Y9(Hv>*b)<_|HB!mzV<0H!iz}QJi`_)bZ67HU#M2de=_V8o91VX#74UEn zj_1cy;eH8=%V??6)3IL4_z1~RuIJAuLuUUtMM3N@ikbO=k&7riLj3y+<5T=cb7FsO z{6(&AdRYIb(qOOIEsF=W0I|RLO&*t1z4)*DS8LkO!|9z0vBzy39xN>{xr$~;9I&rl zsAzsmeG(bRLMM}z43WI_)R!n!5U~U z?KTbs&>coJ`!3LBqLBxb(KM<9WgU%tp!}dw18fVTVH0dKpkY8EW(qA3mPer!HAO~2 zaV)^r3(`hiQCLG|QP@Leo9AOXQzt(qOcG1&MCJj`Jh3vj+>8)|**a7SyuC{a1ySQQ z{tj~!nXQR*+>=JZ+ujeN6*Pq_kmu6h_nd!+zjx(btL>#Lv4rV4aq>Aba59U53|A_C zAJX0hcSJsCE+Aen76>!xew2@Tjb|~8RhG*oI}eGvL7MG)EOUjP(C~fFhZ`tlUK7!= zGjSnv8!lq8E#sWf-H{2({T*4|!xPz&`F?f3Mo^UnE+VtDwpCp#cu>(pz!9|VwZf}o zrtHY-&5B*o;1vu+vl@p88rA(;EzGoS8!m5QUhl|6tAdMLr=;G|3xev}R