Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept spaces in data urls in image urls #267

Closed
wants to merge 3 commits into from
Closed

Accept spaces in data urls in image urls #267

wants to merge 3 commits into from

Conversation

AnnaLena2704
Copy link
Contributor

No description provided.

@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a non-capturing group for (.|\s).

@@ -118,6 +117,7 @@ export class ImageNode extends GraphicsNode {
format = mimeTypeParts[1]

data = match[5]
data = data.replace(/\s/g, '')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do this only in the base64 case. For other data urls, spaces might be desired.

Comment on lines 58 to 59
'test-AL-picture',
'test-AL-arrows',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I think one test case suffices
  • give it a meaningful name like "image-data-urls-base64-spaces"
  • use a smaller image. This is a 1x1 red pixel image:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8DwHwAFBQIAX8jx0gAAAABJRU5ErkJggg==

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants