Skip to content

Commit 1a41c2d

Browse files
committed
Added support for ambiguous ampersands
1 parent 8ca1028 commit 1a41c2d

File tree

7 files changed

+202
-8
lines changed

7 files changed

+202
-8
lines changed

build/html-string.js

Lines changed: 39 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/html-string.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

npm-debug.log

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
0 info it worked if it ends with ok
2+
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'publish' ]
3+
2 info using [email protected]
4+
3 info using [email protected]
5+
4 verbose publish [ '.' ]
6+
5 verbose cache add [ '.', null ]
7+
6 verbose cache add name=undefined spec="." args=[".",null]
8+
7 verbose parsed url { protocol: null,
9+
7 verbose parsed url slashes: null,
10+
7 verbose parsed url auth: null,
11+
7 verbose parsed url host: null,
12+
7 verbose parsed url port: null,
13+
7 verbose parsed url hostname: null,
14+
7 verbose parsed url hash: null,
15+
7 verbose parsed url search: null,
16+
7 verbose parsed url query: null,
17+
7 verbose parsed url pathname: '.',
18+
7 verbose parsed url path: '.',
19+
7 verbose parsed url href: '.' }
20+
8 silly lockFile 3a52ce78- .
21+
9 verbose lock . /home/anthony/.npm/3a52ce78-.lock
22+
10 verbose tar pack [ '/home/anthony/.npm/HTMLString/1.0.6/package.tgz', '.' ]
23+
11 verbose tarball /home/anthony/.npm/HTMLString/1.0.6/package.tgz
24+
12 verbose folder .
25+
13 info prepublish [email protected]
26+
14 silly lockFile 1f1177db-tar tar://.
27+
15 verbose lock tar://. /home/anthony/.npm/1f1177db-tar.lock
28+
16 silly lockFile 423837ce-npm-HTMLString-1-0-6-package-tgz tar:///home/anthony/.npm/HTMLString/1.0.6/package.tgz
29+
17 verbose lock tar:///home/anthony/.npm/HTMLString/1.0.6/package.tgz /home/anthony/.npm/423837ce-npm-HTMLString-1-0-6-package-tgz.lock
30+
18 silly lockFile 1f1177db-tar tar://.
31+
19 silly lockFile 1f1177db-tar tar://.
32+
20 silly lockFile 423837ce-npm-HTMLString-1-0-6-package-tgz tar:///home/anthony/.npm/HTMLString/1.0.6/package.tgz
33+
21 silly lockFile 423837ce-npm-HTMLString-1-0-6-package-tgz tar:///home/anthony/.npm/HTMLString/1.0.6/package.tgz
34+
22 silly lockFile b99c44c8-ony-npm-HTMLString-1-0-6-package /home/anthony/.npm/HTMLString/1.0.6/package
35+
23 verbose lock /home/anthony/.npm/HTMLString/1.0.6/package /home/anthony/.npm/b99c44c8-ony-npm-HTMLString-1-0-6-package.lock
36+
24 silly lockFile b99c44c8-ony-npm-HTMLString-1-0-6-package /home/anthony/.npm/HTMLString/1.0.6/package
37+
25 silly lockFile b99c44c8-ony-npm-HTMLString-1-0-6-package /home/anthony/.npm/HTMLString/1.0.6/package
38+
26 silly lockFile 3a52ce78- .
39+
27 silly lockFile 3a52ce78- .
40+
28 silly publish { name: 'HTMLString',
41+
28 silly publish description: 'An HTML parser written in JavaScript that\'s probably not what you\'re looking for.',
42+
28 silly publish version: '1.0.6',
43+
28 silly publish keywords: [ 'html', 'parser' ],
44+
28 silly publish author:
45+
28 silly publish { name: 'Anthony Blackshaw',
46+
28 silly publish email: '[email protected]',
47+
28 silly publish url: 'https://github.com/anthonyjb' },
48+
28 silly publish main: 'build/html-string.js',
49+
28 silly publish devDependencies:
50+
28 silly publish { grunt: '~0.4.5',
51+
28 silly publish 'grunt-contrib-clean': '^0.6.0',
52+
28 silly publish 'grunt-contrib-coffee': '^0.11.1',
53+
28 silly publish 'grunt-contrib-concat': '^0.5.0',
54+
28 silly publish 'grunt-contrib-jasmine': '^0.9.2',
55+
28 silly publish 'grunt-contrib-uglify': '^0.5.1',
56+
28 silly publish 'grunt-contrib-watch': '^0.6.1' },
57+
28 silly publish scripts: { test: 'grunt jasmine --verbose' },
58+
28 silly publish repository:
59+
28 silly publish { type: 'git',
60+
28 silly publish url: 'https://github.com/GetmeUK/HTMLString.git' },
61+
28 silly publish license: 'MIT',
62+
28 silly publish readme: '# HTMLString\n\n[![Build Status](https://travis-ci.org/GetmeUK/HTMLString.svg?branch=master)](https://travis-ci.org/GetmeUK/HTMLString)\n\n> An HTML parser written in JavaScript that\'s probably not what you\'re looking for.\n\n## Install\n\n**Using bower**\n\n```\nbower install --save HTMLString\n```\n\n**Using npm**\n\n```\nnpm install --save HTMLString\n```\n\n## Building\nTo build the library you\'ll need to use Grunt. First install the required node modules ([grunt-cli](http://gruntjs.com/getting-started) must be installed):\n```\ngit clone https://github.com/GetmeUK/HTMLString.git\ncd HTMLString\nnpm install\n```\n\nThen run `grunt build` to build the project.\n\n## Testing\nTo test the library you\'ll need to use Jasmine. First install Jasmine:\n```\ngit clone https://github.com/pivotal/jasmine.git\nmkdir HTMLString/jasmine\nmv jasmine/dist/jasmine-standalone-2.0.3.zip HTMLString/jasmine\ncd HTMLString/jasmine\nunzip jasmine-standalone-2.0.3.zip\n```\n\nThen open `HTMLString/SpecRunner.html` in a browser to run the tests.\n\nAlternatively you can use `grunt jasmine` to run the tests from the command line.\n\n## Documentation\nFull documentation is available at http://getcontenttools.com/api/html-string\n\n## Browser support\n- Chrome\n- Firefox\n- IE9+\n',
63+
28 silly publish readmeFilename: 'README.md',
64+
28 silly publish gitHead: '8ca1028b8f00c0ae20e25887e57999c7eb6fb03b',
65+
28 silly publish bugs: { url: 'https://github.com/GetmeUK/HTMLString/issues' },
66+
28 silly publish homepage: 'https://github.com/GetmeUK/HTMLString',
67+
28 silly publish _id: '[email protected]',
68+
28 silly publish _shasum: '0dbd2b90ad9ff5634d21f366ecbf9c4954477425',
69+
28 silly publish _from: '.' }
70+
29 verbose request where is /HTMLString
71+
30 verbose request registry https://registry.npmjs.org/
72+
31 verbose request id 9915c72d0522b64e
73+
32 verbose url raw /HTMLString
74+
33 verbose url resolving [ 'https://registry.npmjs.org/', './HTMLString' ]
75+
34 verbose url resolved https://registry.npmjs.org/HTMLString
76+
35 verbose request where is https://registry.npmjs.org/HTMLString
77+
36 info trying registry request attempt 1 at 21:57:55
78+
37 http PUT https://registry.npmjs.org/HTMLString
79+
38 http 401 https://registry.npmjs.org/HTMLString
80+
39 verbose headers { 'content-type': 'application/json',
81+
39 verbose headers 'cache-control': 'max-age=300',
82+
39 verbose headers 'content-length': '42',
83+
39 verbose headers 'accept-ranges': 'bytes',
84+
39 verbose headers date: 'Sun, 23 Oct 2016 20:57:49 GMT',
85+
39 verbose headers via: '1.1 varnish',
86+
39 verbose headers connection: 'keep-alive',
87+
39 verbose headers 'x-served-by': 'cache-lcy1130-LCY',
88+
39 verbose headers 'x-cache': 'MISS',
89+
39 verbose headers 'x-cache-hits': '0',
90+
39 verbose headers 'x-timer': 'S1477256268.696056,VS0,VE1166',
91+
39 verbose headers vary: 'Accept-Encoding' }
92+
40 error publish Failed PUT 401
93+
41 error Error: Could not authenticate getmeuk : HTMLString
94+
41 error at RegClient.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-registry-client/lib/request.js:308:14)
95+
41 error at Request._callback (/usr/local/lib/node_modules/npm/node_modules/npm-registry-client/lib/request.js:246:65)
96+
41 error at Request.self.callback (/usr/local/lib/node_modules/npm/node_modules/request/request.js:236:22)
97+
41 error at Request.emit (events.js:98:17)
98+
41 error at Request.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/request/request.js:1142:14)
99+
41 error at Request.emit (events.js:117:20)
100+
41 error at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/request/request.js:1096:12)
101+
41 error at IncomingMessage.emit (events.js:117:20)
102+
41 error at _stream_readable.js:943:16
103+
41 error at process._tickCallback (node.js:419:13)
104+
42 error If you need help, you may report this *entire* log,
105+
42 error including the npm and node versions, at:
106+
42 error <http://github.com/npm/npm/issues>
107+
43 error System Linux 3.13.0-100-generic
108+
44 error command "/usr/local/bin/node" "/usr/local/bin/npm" "publish"
109+
45 error cwd /home/anthony/Desktop/Work/Public/CoffeeScript/github/HTMLString
110+
46 error node -v v0.10.33
111+
47 error npm -v 1.4.28
112+
48 verbose exit [ 1, true ]

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "HTMLString",
33
"description": "An HTML parser written in JavaScript that's probably not what you're looking for.",
4-
"version": "1.0.6",
4+
"version": "1.0.7",
55
"keywords": [
66
"html",
77
"parser"

spec/html-string-spec.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
Turing: '<q id="turings-quote">Machines take me by <br> <span class="suprised">surprise</span> with <i>great&nbsp;frequency.</i></q>',
99
Wozniak: 'all the best people in life seem to like LINUX.',
1010
WozniakNamespaced: 'all the best people in life seem to like <ns:tag ns:attr="foo">LINUX</ns:tag>.',
11-
WozniakWhitespace: 'all the best people in life seem to like LINUX.'
11+
WozniakWhitespace: 'all the best people in life seem to like LINUX.',
12+
AmbiguousAmpersand: '&amp; &<a href="/foo?bar=1&zee=2&amp;omm=3&end">amp</a> &foo && &&amp; &end'
1213
};
1314

1415
describe('HTMLString.String()', function() {
@@ -22,12 +23,17 @@
2223
string = new HTMLString.String(quotes.WozniakWhitespace, true);
2324
return expect(string.text()).toBe(quotes.WozniakWhitespace);
2425
});
25-
return it('should parse and render a string (HTML)', function() {
26+
it('should parse and render a string (HTML)', function() {
2627
var string;
2728
string = new HTMLString.String(quotes.Turing);
2829
expect(string.html()).toBe(quotes.Turing);
2930
string = new HTMLString.String(quotes.WozniakNamespaced);
30-
expect(string.html()).toBe(quotes.WozniakNamespaced);
31+
return expect(string.html()).toBe(quotes.WozniakNamespaced);
32+
});
33+
return it('should parse and render a string (HTML with ambiguous ampersands)', function() {
34+
var string;
35+
string = new HTMLString.String(quotes.AmbiguousAmpersand);
36+
expect(string.html()).toBe(quotes.AmbiguousAmpersand);
3137
return console.log(string.html());
3238
});
3339
});

src/spec/html-string-spec.coffee

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ all the best people in life seem to like <ns:tag ns:attr="foo">LINUX</ns:tag>.
2121
WozniakWhitespace: '''
2222
all the best people in life seem to like LINUX.
2323
'''
24+
AmbiguousAmpersand: '''
25+
&amp; &<a href="/foo?bar=1&zee=2&amp;omm=3&end">amp</a> &foo && &&amp; &end
26+
'''
2427
}
2528

2629
describe 'HTMLString.String()', () ->
@@ -41,6 +44,10 @@ describe 'HTMLString.String()', () ->
4144
string = new HTMLString.String(quotes.WozniakNamespaced)
4245
expect(string.html()).toBe quotes.WozniakNamespaced
4346

47+
it 'should parse and render a string (HTML with ambiguous ampersands)', () ->
48+
string = new HTMLString.String(quotes.AmbiguousAmpersand)
49+
expect(string.html()).toBe quotes.AmbiguousAmpersand
50+
4451
console.log string.html()
4552

4653

src/strings.coffee

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,7 @@ class _Parser
659659

660660
@fsm.addTransition '<', CHAR_OR_ENTITY_OR_TAG, OPENNING_OR_CLOSING_TAG
661661
@fsm.addTransition '&', CHAR_OR_ENTITY_OR_TAG, ENTITY
662+
@fsm.addTransition 'END', CHAR_OR_ENTITY_OR_TAG, null
662663

663664
# Entity
664665
@fsm.addTransitions ENTITY_CHARS, ENTITY, null, (c) ->
@@ -668,6 +669,19 @@ class _Parser
668669
@_pushChar("&#{ @entity };")
669670
@entity = ''
670671

672+
@fsm.addTransitionAny ENTITY, CHAR_OR_ENTITY_OR_TAG, (c) ->
673+
@_pushChar('&')
674+
for c in @entity.split('')
675+
@_pushChar(c)
676+
@entity = ''
677+
@_back()
678+
679+
@fsm.addTransition 'END', ENTITY, null, () ->
680+
@_pushChar('&')
681+
for c in @entity.split('')
682+
@_pushChar(c)
683+
@entity = ''
684+
671685
# Opening or closing Tag
672686
@fsm.addTransitions [' ', '\n'], OPENNING_OR_CLOSING_TAG
673687
@fsm.addTransitions ALPHA_CHARS, OPENNING_OR_CLOSING_TAG, OPENING_TAG, () ->
@@ -779,7 +793,7 @@ class _Parser
779793
@fsm.addTransitions ENTITY_CHARS, ATTR_ENTITY_NO_DELIM, null, (c) ->
780794
@entity += c
781795

782-
@fsm.addTransitions ENTITY_CHARS, ATTR_ENTITY_SINGLE_DELIM, (c) ->
796+
@fsm.addTransitions ENTITY_CHARS, ATTR_ENTITY_SINGLE_DELIM, null, (c) ->
783797
@entity += c
784798

785799
@fsm.addTransitions ENTITY_CHARS, ATTR_ENTITY_DOUBLE_DELIM, null, (c) ->
@@ -797,6 +811,21 @@ class _Parser
797811
@attributeValue += "&#{ @entity };"
798812
@entity = ''
799813

814+
@fsm.addTransitionAny ATTR_ENTITY_NO_DELIM, ATTR_VALUE_NO_DELIM, (c) ->
815+
@attributeValue += '&' + @entity
816+
@entity = ''
817+
@_back()
818+
819+
@fsm.addTransitionAny ATTR_ENTITY_SINGLE_DELIM, ATTR_VALUE_SINGLE_DELIM, (c) ->
820+
@attributeValue += '&' + @entity
821+
@entity = ''
822+
@_back()
823+
824+
@fsm.addTransitionAny ATTR_ENTITY_DOUBLE_DELIM, ATTR_VALUE_DOUBLE_DELIM, (c) ->
825+
@attributeValue += '&' + @entity
826+
@entity = ''
827+
@_back()
828+
800829
# Parsing methods
801830

802831
_back: () ->
@@ -896,6 +925,8 @@ class _Parser
896925

897926
@head++
898927

928+
@fsm.process('END')
929+
899930
return @string
900931

901932
preprocess: (html) ->

0 commit comments

Comments
 (0)