Skip to content

Commit e521b11

Browse files
authored
Merge pull request #14 from jczerwinski/allow-blank-mime
Support parsing of datauri's without mediatype. Also tag as 0.2.5
2 parents 5873c82 + eded3c0 commit e521b11

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
CHANGELOG
22
---------
33

4+
- **0.2.5 (2018-02-27)**
5+
6+
- Support parsing of datauri's without mediatype.
7+
48
- **0.1.1 (2014-08-22)**
59

610
- Fix parsing of mime types that contains a plus sign and a dot.

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "data-uri/data-uri",
3+
"version": "0.2.5",
34
"type": "library",
45
"description": "PHP DataURI component",
56
"keywords": ["data-uri", "data", "URI"],

src/DataURI/Parser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Parser
3838
* offset #2 Parameters
3939
* offset #3 Datas
4040
*/
41-
const DATA_URI_REGEXP = '/data:([a-zA-Z-\/+]+)([a-zA-Z0-9-_;=.+]+)?,(.*)/';
41+
const DATA_URI_REGEXP = '/data:([a-zA-Z-\/+]*)([a-zA-Z0-9-_;=.+]+)?,(.*)/';
4242

4343
/**
4444
* Parse a data URI and return a DataUri\Data
@@ -60,7 +60,7 @@ public static function parse($dataUri, $len = Data::TAGLEN, $strict = false)
6060

6161
$base64 = false;
6262

63-
$mimeType = $matches[1];
63+
$mimeType = $matches[1] ? $matches[1] : null;
6464
$params = $matches[2];
6565
$rawData = $matches[3];
6666

tests/ParserTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public function testParse()
3838
"data:text/plain;charset=utf-8,%23%24%25",
3939
"data:application/vnd-xxx-query,select_vcount,fcol_from_fieldtable/local",
4040
"data:image/svg+xml;base64," . $b64,
41-
"data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64," . $b64
41+
"data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64," . $b64,
42+
"data:;base64," . $b64,
4243
);
4344

4445
$dataURI = DataURI\Parser::parse($tests[0]);
@@ -61,6 +62,9 @@ public function testParse()
6162

6263
$dataURI = DataURI\Parser::parse($tests[4]);
6364
$this->assertEquals('image/svg+xml', $dataURI->getMimeType());
65+
66+
$dataURI = DataURI\Parser::parse($tests[6]);
67+
$this->assertEquals('text/plain', $dataURI->getMimeType());
6468
}
6569

6670
/**

0 commit comments

Comments
 (0)