Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] [fix #702] Validate content of <dc:language> #807

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ static Map<MessageId, Severity> getDefaultSeverities()
map.put(MessageId.OPF_082, Severity.ERROR);
map.put(MessageId.OPF_083, Severity.ERROR);
map.put(MessageId.OPF_084, Severity.ERROR);
map.put(MessageId.OPF_085, Severity.INFO);
map.put(MessageId.OPF_086, Severity.ERROR);

// PKG
map.put(MessageId.PKG_001, Severity.WARNING);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/adobe/epubcheck/messages/MessageId.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ public enum MessageId implements Comparable<MessageId>
OPF_082("OPF-082"),
OPF_083("OPF-083"),
OPF_084("OPF-084"),
OPF_085("OPF-085"),
OPF_086("OPF-086"),

// Messages relating to the entire package
PKG_001("PKG-001"),
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Set;

import com.adobe.epubcheck.api.EPUBLocation;
Expand Down Expand Up @@ -89,6 +90,7 @@ public void runChecks()
checkSemantics();
checkNav();
checkSpecifics();
checkLanguage();
}

@Override
Expand Down Expand Up @@ -395,6 +397,26 @@ private void checkPagination()
}
}

private void checkLanguage() {
Set<Metadata> dcLanguageMetas = ((OPFHandler30) opfHandler).getMetadata()
.getPrimary(DCMESVocab.VOCAB.get(DCMESVocab.PROPERTIES.LANGUAGE));
if (!dcLanguageMetas.isEmpty())
{
for(Metadata metadata : dcLanguageMetas)
{
Locale l = Locale.forLanguageTag(metadata.getValue());
if (l == null || l.getLanguage().length() > 3) {
report.message(MessageId.OPF_086, EPUBLocation.create(path), metadata.getValue());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.
A more thorough validation would be to use IANA’s language tag registry, but this is probably overkill?

}
else if (!l.getVariant().isEmpty())
{
report.message(MessageId.OPF_085, EPUBLocation.create(path), metadata.getValue());
}
}
}

}

private void checkSemantics()
{
if (context.profile == EPUBProfile.EDUPUB || context.pubTypes.contains(OPFData.DC_TYPE_EDUPUB))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ OPF_081=Resource '%1$s' (referenced from an EPUB Dictionary collection) was not
OPF_082=Found an EPUB Dictionary collection containing more than one Search Key Map Document.
OPF_083=Found an EPUB Dictionary collection containing no Search Key Map Document.
OPF_084=Found an EPUB Dictionary collection containing resource '%1$s' which is neither a Search Key Map Document nor an XHTML Content Document.
OPF_085=Using language with variant in package description '%1$s'
OPF_086=Incorrect language in package description '%1$s'


#Package
PKG_001=Validating the EPUB against version %1$s but detected version %2$s.
Expand Down
13 changes: 10 additions & 3 deletions src/test/java/com/adobe/epubcheck/api/Epub30CheckExpandedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,7 @@ public void testIssue189()
@Test
public void testIssue198()
{
// Collections.addAll(expectedErrors, );

Collections.addAll(expectedErrors, MessageId.OPF_086);
// also data-* removal
testValidateDocument("valid/issue198/");
}
Expand Down Expand Up @@ -607,7 +606,15 @@ public void testIssue5()
{
testValidateDocument("valid/issue567/");
}


@Test
public void testIssue702()
{
Collections.addAll(expectedErrors, MessageId.OPF_086);
Collections.addAll(expectedInfos, MessageId.OPF_085);
testValidateDocument("valid/issue702/");
}

@Test
public void testIssue615_langtag() {
testValidateDocument("valid/issue615-langtags/");
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/adobe/epubcheck/cli/CLITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void testInvalidExp()
@Test
public void testValidSingle()
{
assertEquals(0, run(new String[]{singlePath + "nav/valid/nav001.xhtml", "-mode", "nav"},true));
assertEquals(0, run(new String[]{singlePath + "nav/valid/nav001.xhtml", "-mode", "nav"}));
}

@Test
Expand Down
6 changes: 6 additions & 0 deletions src/test/resources/30/expanded/valid/issue702/EPUB/lorem.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
body {
margin-left : 6em;
margin-right : 16em;
color:black;
font-family: arial, helvetica, sans-serif;
}
19 changes: 19 additions & 0 deletions src/test/resources/30/expanded/valid/issue702/EPUB/lorem.opf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" unique-identifier="uid">
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:identifier id="uid">urn:uuid:550e8400-e29b-41d4-a716-4466674412314</dc:identifier>
<dc:title>Lorem Ipsum</dc:title>
<dc:language>en-US</dc:language>
<dc:language>en-US-POSIX</dc:language>
<dc:language>invalid-language</dc:language>
<dc:date>2011-09-01</dc:date>
<meta property="dcterms:modified">2011-09-01T17:18:00Z</meta>
</metadata>
<manifest>
<item id="t1" href="lorem.xhtml" properties="nav" media-type="application/xhtml+xml" />
<item id="css" href="lorem.css" media-type="text/css" />
</manifest>
<spine>
<itemref idref="t1" />
</spine>
</package>
109 changes: 109 additions & 0 deletions src/test/resources/30/expanded/valid/issue702/EPUB/lorem.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="la" lang="la"
xmlns:epub="http://www.idpf.org/2007/ops">
<head>
<title>Lorem Ipsum</title>
<link type="text/css" rel="stylesheet" href="lorem.css" />
<meta name="viewport" content="width=device-width" />
</head>
<body>
<h1>Lorem Ipsum</h1>
<section>
<h2>Table of Contents</h2>
<nav epub:type="toc">
<ol>
<li><a href="#ch1">Chapter 1</a></li>
<li><a href="#ch2">Chapter 2</a></li>
</ol>
</nav>
</section>
<section id="ch1">
<h2>Chapter 1</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam vel purus mauris, ut
auctor massa. Pellentesque non nunc risus. Fusce a massa augue. Nunc erat ante,
auctor id varius ac, vestibulum non purus. Quisque non dui in sem consectetur
condimentum non ac quam. Quisque ultricies nulla nec urna fringilla pretium.
Pellentesque dictum pulvinar purus in mattis. Aliquam vestibulum orci sed magna
vestibulum a sollicitudin lectus pharetra. Suspendisse luctus risus imperdiet nunc
condimentum malesuada. Nulla fringilla vulputate vestibulum. Sed diam dui, fringilla
quis sagittis nec, viverra et nibh.</p>

<p>Sed sollicitudin accumsan augue, quis pulvinar sem volutpat at. Vestibulum rutrum
bibendum augue sit amet accumsan. Etiam tempus malesuada libero vestibulum
fringilla. Maecenas diam nulla, ultricies ac sodales vitae, viverra ut velit.
Vivamus posuere, mi sit amet vehicula tempus, nibh purus scelerisque enim, non
vestibulum erat arcu in libero. Aliquam vel convallis nibh. Sed in nisi ipsum. Sed
sed est justo, in lacinia nulla.</p>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed luctus est vel lacus
ullamcorper vestibulum. Mauris est sapien, pharetra id feugiat in, ornare a erat.
Nam consectetur vehicula nisi vel faucibus. Morbi blandit augue nec lacus malesuada
venenatis. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur
ridiculus mus. Maecenas consectetur, odio vitae suscipit ullamcorper, arcu ligula
pellentesque sem, quis rhoncus enim eros id lectus. Nam ornare dui est, vel posuere
metus. Quisque non nisl metus. Pellentesque id mi nunc, in gravida metus. Nullam
neque tellus, ultricies quis laoreet vitae, imperdiet at nunc. Ut laoreet massa quis
quam vulputate et ultricies nibh consectetur. Donec convallis, nulla id ultricies
ullamcorper, diam tortor interdum dolor, vel tempor lectus urna ut est. Praesent
convallis lacus vitae justo lobortis euismod. In at ante elit.</p>

<p>Aenean quis consectetur justo. Nulla nec enim nisl. Etiam rutrum volutpat tellus, a
scelerisque mauris malesuada sit amet. Suspendisse quis urna augue. Proin tempus
hendrerit libero non cursus. Praesent non massa at nisl luctus facilisis. Nullam
pulvinar, ligula eu porta ornare, mi mi accumsan orci, a iaculis tortor lorem quis
dolor. Phasellus ante nibh, pulvinar ac pulvinar eu, pulvinar ac enim.</p>

<p>Donec vel velit id elit volutpat vestibulum vitae a erat. Duis id est id magna
aliquam pretium nec sit amet nibh. Nullam condimentum suscipit felis, sed interdum
felis dictum ac. Phasellus non nisi quis magna pellentesque auctor. Cras risus
lectus, viverra eu fringilla malesuada, rhoncus et est. Etiam rhoncus pharetra
accumsan. Nullam suscipit tellus felis.</p>
</section>
<section id="ch2">
<h2>Chapter 2</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla laoreet nibh felis.
Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia
Curae; Etiam est sapien, dapibus eget gravida nec, accumsan a turpis. Nunc in nisi
ut dolor elementum porttitor. Mauris hendrerit pulvinar tincidunt. Etiam metus
metus, ullamcorper ut varius lacinia, luctus et nibh. Donec ut metus enim, id
faucibus nunc. Quisque ut iaculis mauris. Duis pellentesque nulla ut eros ultricies
quis condimentum eros adipiscing. Sed porta ultrices diam, ut sagittis lectus mattis
a. Phasellus gravida, sapien vitae mollis interdum, dui neque tempor arcu, ac ornare
leo ipsum ut nisl.</p>

<p>Donec porta, odio et aliquet molestie, felis tellus fermentum leo, id interdum magna
massa quis ligula. Integer elementum mauris eget nisl eleifend facilisis nec sit
amet tellus. Morbi consectetur dignissim egestas. Donec pulvinar, enim eu auctor
cursus, turpis arcu venenatis turpis, eu cursus magna nisl sit amet ante. Curabitur
eleifend arcu eget nibh facilisis mattis. Etiam nisl nunc, semper vitae condimentum
sed, viverra sit amet lacus. Curabitur et orci augue. Suspendisse sollicitudin
vulputate risus, sit amet consequat erat mollis eu. Nunc sodales tincidunt
tincidunt.</p>

<p>Aliquam erat volutpat. Aliquam ornare augue et nulla consequat commodo. Quisque
dictum rhoncus orci vel euismod. Proin leo turpis, adipiscing quis facilisis id,
condimentum sed metus. Nullam pellentesque scelerisque est nec tristique. Nunc augue
turpis, consequat non varius quis, aliquam auctor dolor. Cras luctus dignissim justo
sit amet laoreet. Quisque vel ipsum quis massa suscipit vehicula.</p>

<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis
egestas. Vivamus fringilla eleifend magna, vel commodo turpis egestas at.
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis
egestas. Sed eu lorem quam, et sagittis libero. Maecenas vel ante id sem bibendum
laoreet nec dignissim justo. Class aptent taciti sociosqu ad litora torquent per
conubia nostra, per inceptos himenaeos. Fusce eu lorem orci, eu viverra nisi. Lorem
ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum dapibus commodo
pellentesque. Maecenas quis est accumsan est interdum pharetra egestas nec lorem.
Nam a lectus sit amet justo facilisis suscipit.</p>

<p>Integer dolor dolor, volutpat id commodo id, gravida id risus. Donec consectetur
sollicitudin sem, non auctor urna pulvinar non. Vivamus ipsum nisi, commodo sed
scelerisque id, porta nec massa. Vestibulum ac risus et augue faucibus fermentum ut
et nisi. Integer tincidunt suscipit ipsum, sed interdum felis mollis sed.
Suspendisse potenti. Praesent et mauris et quam consequat tristique. Morbi mi dolor,
pharetra quis rutrum quis, fringilla in tortor. Sed a nulla vitae leo dapibus
cursus. Aliquam erat volutpat. Integer purus purus, dictum id bibendum at, lobortis
quis metus.</p>
</section>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<container xmlns="urn:oasis:names:tc:opendocument:xmlns:container" version="1.0">
<rootfiles>
<rootfile full-path="EPUB/lorem.opf"
media-type="application/oebps-package+xml"/>
</rootfiles>
</container>
1 change: 1 addition & 0 deletions src/test/resources/30/expanded/valid/issue702/mimetype
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
application/epub+zip