Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

some malformed html tests

  • Loading branch information...
commit ea6fe895e99188d8d67abb59c8bcf3838a3779a5 1 parent 72eb8be
tmont authored
View
3  debug-mocha.js
@@ -16,8 +16,7 @@ fs.readdir(testDir, function(err, files) {
return;
}
files.forEach(function (file) {
-// if (/text-tests.js$/.test(file)) {
- if (path.extname(file) === '.js') {
+ if (/-tests\.js$/.test(file)) {
console.log('adding test file: %s', file);
mocha.addFile(testDir + file);
}
View
7 src/parser.js
@@ -235,7 +235,7 @@ function parseNext(context) {
parseEndElement(context);
} else {
//malformed html, let it slide through
- appendText(buffer);
+ appendText(buffer, context);
}
}
else if (context.current === '!') {
@@ -247,7 +247,7 @@ function parseNext(context) {
parseComment(context);
} else {
//malformed html
- appendText(buffer + '!');
+ appendText(buffer + '!', context);
}
}
else if (regexes.elementName.test(context.current)) {
@@ -256,7 +256,8 @@ function parseNext(context) {
}
else {
//malformed html, let it slide through
- appendText(buffer);
+ context.read();
+ appendText(buffer, context);
}
break;
View
2  test.sh
@@ -12,5 +12,5 @@ else
CMD="$CMD dot"
fi
-CMD="$CMD ./tests/*"
+CMD="$CMD ./tests"
$CMD
View
38 tests/malformed-tests.js
@@ -0,0 +1,38 @@
+var should = require('should');
+var helpers = require('./helpers');
+
+describe('Malformed HTML', function() {
+ it('unescaped < in text should not be an open tag', function() {
+ var openCount = 0, textCount = 0;
+ helpers.parseString('5 < 4 == false', {
+ openElement: function(name, context) {
+ openCount++;
+ },
+
+ text: function(value, context) {
+ value.should.equal('5 < 4 == false');
+ textCount++;
+ }
+ });
+
+ openCount.should.equal(0);
+ textCount.should.equal(1);
+ });
+
+ it('< followed by a letter without a following > is still a tag', function() {
+ var openCount = 0, textCount = 0;
+ helpers.parseString('< foo', {
+ openElement: function(name, context) {
+ name.should.equal('foo');
+ openCount++;
+ },
+
+ text: function(value, context) {
+ textCount++;
+ }
+ });
+
+ openCount.should.equal(1);
+ textCount.should.equal(0);
+ });
+});
View
19 tests/open-and-close-tag-tests.js
@@ -34,6 +34,25 @@ describe('opening and closing tags', function() {
closeCount.should.equal(1);
});
+ it('tag names can start with _', function() {
+ var openCount = 0, closeCount = 0;
+ helpers.parseString('<_foo></_foo>', {
+ openElement: function(name, context) {
+ name.should.equal('_foo');
+ helpers.verifyContext(1, 2, context);
+ openCount++;
+ },
+ closeElement: function(name, context) {
+ name.should.equal('_foo');
+ helpers.verifyContext(1, 9, context);
+ closeCount++;
+ }
+ });
+
+ openCount.should.equal(1);
+ closeCount.should.equal(1);
+ });
+
it('opening and closing tag mismatch', function() {
var openCount = 0, closeCount = 0;
helpers.parseString('<foo></bar>', {
Please sign in to comment.
Something went wrong with that request. Please try again.