Skip to content

Commit

Permalink
Fix 2112 (#2113)
Browse files Browse the repository at this point in the history
* Update base64.spec.js

* Update base64.spec.js

* Update addimage.js

* just test against 8.9,4

It doesnt even have specific node code
  • Loading branch information
Uzlopak committed Dec 7, 2018
1 parent 9b6a8f6 commit c5e2609
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
1 change: 0 additions & 1 deletion .travis.yml
@@ -1,7 +1,6 @@
language: node_js
node_js:
- "8.9.4"
- "10"
install:
- npm -g install yarn
- yarn
Expand Down
44 changes: 24 additions & 20 deletions src/modules/addimage.js
Expand Up @@ -421,26 +421,30 @@
*
* @returns {boolean}
*/
jsPDFAPI.validateStringAsBase64 = function(possibleBase64String) {
possibleBase64String = possibleBase64String || '';

var result = true;

if (possibleBase64String.length % 4 !== 0) {
result = false;
}

if (/[A-Za-z0-9\/]+/.test(possibleBase64String.substr(0, possibleBase64String.length - 2)) === false) {
result = false;
}


if (/[A-Za-z0-9\/][A-Za-z0-9+\/]|[A-Za-z0-9+\/]=|==/.test(possibleBase64String.substr(-2)) === false) {
result = false;
}
return result;
};

jsPDFAPI.validateStringAsBase64 = function(possibleBase64String) {
possibleBase64String = possibleBase64String || '';
possibleBase64String.toString().trim();

var result = true;

if (possibleBase64String.length === 0) {
result = false;
}

if (possibleBase64String.length % 4 !== 0) {
result = false;
}

if (/^[A-Za-z0-9+\/]+$/.test(possibleBase64String.substr(0, possibleBase64String.length - 2)) === false) {
result = false;
}


if (/^[A-Za-z0-9\/][A-Za-z0-9+\/]|[A-Za-z0-9+\/]=|==$/.test(possibleBase64String.substr(-2)) === false) {
result = false;
}
return result;
};
/**
* Strips out and returns info from a valid base64 data URI
*
Expand Down
6 changes: 4 additions & 2 deletions tests/addimage/base64.spec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c5e2609

Please sign in to comment.