Skip to content

Commit

Permalink
Fixes isue jshttp#13
Browse files Browse the repository at this point in the history
  • Loading branch information
rg2011 committed Jan 28, 2024
1 parent d8c38b1 commit fc413d3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
* ; specify a structured syntax suffix
* ALPHA = %x41-5A / %x61-7A ; A-Z / a-z
* DIGIT = %x30-39 ; 0-9
* OWS = *( SP / HTAB ) ; might be surrounded by optional whitespace
*/
var SUBTYPE_NAME_REGEXP = /^[A-Za-z0-9][A-Za-z0-9!#$&^_.-]{0,126}$/
var TYPE_NAME_REGEXP = /^[A-Za-z0-9][A-Za-z0-9!#$&^_-]{0,126}$/
var TYPE_REGEXP = /^ *([A-Za-z0-9][A-Za-z0-9!#$&^_-]{0,126})\/([A-Za-z0-9][A-Za-z0-9!#$&^_.+-]{0,126}) *$/
var TYPE_REGEXP = /^[ \t]*([A-Za-z0-9][A-Za-z0-9!#$&^_-]{0,126})\/([A-Za-z0-9][A-Za-z0-9!#$&^_.+-]{0,126})[ \t]*$/

/**
* Module exports.
Expand Down
12 changes: 12 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ describe('typer.parse(string)', function () {
assert.strictEqual(type.suffix, 'xml')
})

it('should support spaces', function () {
var type = typer.parse(' image/svg ')
assert.strictEqual(type.type, 'image')
assert.strictEqual(type.subtype, 'svg')
})

it('should support tabs', function () {
var type = typer.parse("\ttext/html\t")
assert.strictEqual(type.type, 'text')
assert.strictEqual(type.subtype, 'html')
})

it('should lower-case type', function () {
var type = typer.parse('IMAGE/SVG+XML')
assert.strictEqual(type.type, 'image')
Expand Down

0 comments on commit fc413d3

Please sign in to comment.