Commit 8aaa8015 authored by David Sveningsson's avatar David Sveningsson

feat(elements): <head> requires <title>

parent 664dead7
......@@ -11,31 +11,33 @@ Array [
Object {
"column": 2,
"context": Object {
"missing": "head",
"missing": "body",
"node": "html",
},
"line": 1,
"message": "<html> element must have <head> as content",
"message": "<html> element must have <body> as content",
"offset": 1,
"ruleId": "element-required-content",
"severity": 2,
"size": 4,
},
Object {
"column": 2,
"column": 6,
"context": Object {
"missing": "body",
"node": "html",
"missing": "title",
"node": "head",
},
"line": 1,
"message": "<html> element must have <body> as content",
"offset": 1,
"line": 2,
"message": "<head> element must have <title> as content",
"offset": 12,
"ruleId": "element-required-content",
"severity": 2,
"size": 4,
},
],
"source": "<html>
<head>
</head>
</html>",
"warningCount": 0,
},
......
......@@ -2,9 +2,13 @@ import HtmlValidate from "../../../src/htmlvalidate";
const markup: { [key: string]: string } = {};
markup["incorrect"] = `<html>
<head>
</head>
</html>`;
markup["correct"] = `<html>
<head></head>
<head>
<title>foo</title>
</head>
<body></body>
</html>`;
......
......@@ -25,6 +25,8 @@ Examples of **incorrect** code for this rule:
<validate name="incorrect" rules="element-required-content">
<html>
<head>
</head>
</html>
</validate>
......@@ -32,7 +34,9 @@ Examples of **correct** code for this rule:
<validate name="correct" rules="element-required-content">
<html>
<head></head>
<head>
<title>foo</title>
</head>
<body></body>
</html>
</validate>
......@@ -2217,7 +2217,7 @@ exports[`HTML elements <h6> valid markup 1`] = `Array []`;
exports[`HTML elements <head> invalid markup 1`] = `
Array [
Object {
"errorCount": 5,
"errorCount": 6,
"filePath": "test-files/elements/head-invalid.html",
"messages": Array [
Object {
......@@ -2230,12 +2230,25 @@ Array [
"severity": 2,
"size": 4,
},
Object {
"column": 3,
"context": Object {
"missing": "title",
"node": "head",
},
"line": 10,
"message": "<head> element must have <title> as content",
"offset": 147,
"ruleId": "element-required-content",
"severity": 2,
"size": 4,
},
Object {
"column": 4,
"context": undefined,
"line": 9,
"line": 19,
"message": "Element <div> is not permitted as content in <head>",
"offset": 146,
"offset": 278,
"ruleId": "element-permitted-content",
"severity": 2,
"size": 3,
......@@ -2243,9 +2256,9 @@ Array [
Object {
"column": 4,
"context": undefined,
"line": 10,
"line": 20,
"message": "Element <span> is not permitted as content in <head>",
"offset": 160,
"offset": 292,
"ruleId": "element-permitted-content",
"severity": 2,
"size": 4,
......@@ -2253,9 +2266,9 @@ Array [
Object {
"column": 4,
"context": undefined,
"line": 19,
"line": 30,
"message": "Element <base> can only appear once under <head>",
"offset": 282,
"offset": 435,
"ruleId": "element-permitted-occurrences",
"severity": 2,
"size": 4,
......@@ -2263,9 +2276,9 @@ Array [
Object {
"column": 4,
"context": undefined,
"line": 28,
"line": 39,
"message": "Element <title> can only appear once under <head>",
"offset": 417,
"offset": 571,
"ruleId": "element-permitted-occurrences",
"severity": 2,
"size": 5,
......@@ -2273,12 +2286,22 @@ Array [
],
"source": "<!-- should not be allowed outside <html> -->
<div>
<head></head>
<head>
<title>foo</title>
</head>
</div>
<!-- should require title -->
<html lang=\\"en\\">
<head>
</head>
<body></body>
</html>
<!-- should not allow flow or phrasing -->
<html lang=\\"en\\">
<head>
<title>foo</title>
<div></div>
<span></span>
</head>
......@@ -2288,13 +2311,14 @@ Array [
<!-- should only allow <base> once -->
<html lang=\\"en\\">
<head>
<title>foo</title>
<base>
<base>
</head>
<body></body>
</html>
<!-- should only allow <titl> once -->
<!-- should only allow <title> once -->
<html lang=\\"en\\">
<head>
<title>lorem ipsum</title>
......@@ -2453,9 +2477,9 @@ Array [
"missing": "head",
"node": "html",
},
"line": 8,
"line": 10,
"message": "<html> element must have <head> as content",
"offset": 118,
"offset": 141,
"ruleId": "element-required-content",
"severity": 2,
"size": 4,
......@@ -2466,9 +2490,9 @@ Array [
"missing": "body",
"node": "html",
},
"line": 8,
"line": 10,
"message": "<html> element must have <body> as content",
"offset": 118,
"offset": 141,
"ruleId": "element-required-content",
"severity": 2,
"size": 4,
......@@ -2476,9 +2500,9 @@ Array [
Object {
"column": 3,
"context": undefined,
"line": 14,
"line": 18,
"message": "Element <head> can only appear once under <html>",
"offset": 217,
"offset": 263,
"ruleId": "element-permitted-occurrences",
"severity": 2,
"size": 4,
......@@ -2486,9 +2510,9 @@ Array [
Object {
"column": 3,
"context": undefined,
"line": 22,
"line": 30,
"message": "Element <body> can only appear once under <html>",
"offset": 343,
"offset": 435,
"ruleId": "element-permitted-occurrences",
"severity": 2,
"size": 4,
......@@ -2496,9 +2520,9 @@ Array [
Object {
"column": 3,
"context": undefined,
"line": 28,
"line": 36,
"message": "Element <head> must be used before <body> in this context",
"offset": 442,
"offset": 534,
"ruleId": "element-permitted-order",
"severity": 2,
"size": 4,
......@@ -2506,7 +2530,9 @@ Array [
],
"source": "<!-- should require lang -->
<html>
<head></head>
<head>
<title>foo</title>
</head>
<body></body>
</html>
......@@ -2516,14 +2542,20 @@ Array [
<!-- should not allow multiple head -->
<html lang=\\"en\\">
<head></head>
<head></head>
<head>
<title>foo</title>
</head>
<head>
<title>bar</title>
</head>
<body></body>
</html>
<!-- should not allow multiple body -->
<html lang=\\"en\\">
<head></head>
<head>
<title>foo</title>
</head>
<body></body>
<body></body>
</html>
......@@ -2531,7 +2563,9 @@ Array [
<!-- should not allow body before head -->
<html lang=\\"en\\">
<body></body>
<head></head>
<head>
<title>foo</title>
</head>
</html>
",
"warningCount": 0,
......
......@@ -388,7 +388,8 @@
"head": {
"deprecatedAttributes": ["profile"],
"permittedContent": ["base?", "title?", "@meta"]
"permittedContent": ["base?", "title?", "@meta"],
"requiredContent": ["title"]
},
"header": {
......
......@@ -12,7 +12,7 @@ describe("rule element-required-content", () => {
it("should not report error when element has all required content", () => {
const report = htmlvalidate.validateString(
"<html><head></head><body></body></html>"
"<html><head><title></title></head><body></body></html>"
);
expect(report).toBeValid();
});
......
<!-- should be allowed under <head> -->
<head>
<title>foo</title>
<base>
</head>
<!-- should be allowed under <html> -->
<html lang="en">
<head></head>
<head>
<title>foo</title>
</head>
<body></body>
</html>
<!-- should not be allowed outside <html> -->
<div>
<head></head>
<head>
<title>foo</title>
</head>
</div>
<!-- should require title -->
<html lang="en">
<head>
</head>
<body></body>
</html>
<!-- should not allow flow or phrasing -->
<html lang="en">
<head>
<title>foo</title>
<div></div>
<span></span>
</head>
......@@ -15,13 +25,14 @@
<!-- should only allow <base> once -->
<html lang="en">
<head>
<title>foo</title>
<base>
<base>
</head>
<body></body>
</html>
<!-- should only allow <titl> once -->
<!-- should only allow <title> once -->
<html lang="en">
<head>
<title>lorem ipsum</title>
......
<!-- should be allowed under <html> -->
<html lang="en">
<head></head>
<head>
<title>foo</title>
</head>
<body></body>
</html>
......
<!-- should require lang -->
<html>
<head></head>
<head>
<title>foo</title>
</head>
<body></body>
</html>
......@@ -10,14 +12,20 @@
<!-- should not allow multiple head -->
<html lang="en">
<head></head>
<head></head>
<head>
<title>foo</title>
</head>
<head>
<title>bar</title>
</head>
<body></body>
</html>
<!-- should not allow multiple body -->
<html lang="en">
<head></head>
<head>
<title>foo</title>
</head>
<body></body>
<body></body>
</html>
......@@ -25,5 +33,7 @@
<!-- should not allow body before head -->
<html lang="en">
<body></body>
<head></head>
<head>
<title>foo</title>
</head>
</html>
<!-- well structured -->
<html lang="en">
<head></head>
<head>
<title>foo</title>
</head>
<body></body>
</html>
<head>
<title>foo</title>
<script>
document.write('<div>');
</script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment