Skip to content

Commit

Permalink
fix: improve checking of missing SVG link labels, now USAGE
Browse files Browse the repository at this point in the history
This commit changes the severity of error `ACC-011` to USAGE (was WARNING).
Labelling links is not strictly a spec requirement, and checking for
missing labels should be done with specialized accessibility inspection.

The check is still available, with an improved logic: the link is
reported as having a missing accessible label only if:
- it does not have an `xlink:title` attribute
- AND it does not have an `aria-label` attribute
- AND it does not have a `title` element child
- AND it does not have a `text` element child

Note that his logic is incomplete, as it does not check that the content
of `title` or `text` children is not empty. But reporting links that
have none of the above can be somewhat useful as a simplified first-pass
accessibility check.

Fix #1353
  • Loading branch information
rdeltour committed Nov 27, 2022
1 parent cc50e3d commit 5903626
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private void initialize()
severities.put(MessageId.ACC_008, Severity.SUPPRESSED);
severities.put(MessageId.ACC_009, Severity.USAGE);
severities.put(MessageId.ACC_010, Severity.SUPPRESSED);
severities.put(MessageId.ACC_011, Severity.WARNING);
severities.put(MessageId.ACC_011, Severity.USAGE);
severities.put(MessageId.ACC_012, Severity.SUPPRESSED);
severities.put(MessageId.ACC_013, Severity.SUPPRESSED);
severities.put(MessageId.ACC_014, Severity.SUPPRESSED);
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/com/adobe/epubcheck/ops/OPSHandler30.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public class OPSHandler30 extends OPSHandler
protected boolean inRegionBasedNav = false;
protected boolean isOutermostSVGAlreadyProcessed = false;
protected boolean hasAltorAnnotation = false;
protected boolean hasTitle = false;
protected boolean hasLabel = false;
protected boolean hasViewport = false;

static protected final String[] scriptEventsStrings = { "onafterprint", "onbeforeprint",
Expand Down Expand Up @@ -399,7 +399,11 @@ else if (name.equals("source"))
}
else if ("http://www.w3.org/2000/svg".equals(e.getNamespace()) && name.equals("title"))
{
hasTitle = true;
hasLabel = true;
}
else if ("http://www.w3.org/2000/svg".equals(e.getNamespace()) && name.equals("text"))
{
hasLabel = true;
}

processInlineScripts();
Expand Down Expand Up @@ -491,8 +495,9 @@ protected void processAnchor(XMLElement e)
}
if (inSvg || context.mimeType.equals("image/svg+xml"))
{
hasTitle = Strings
.emptyToNull(e.getAttributeNS(EpubConstants.XLinkNamespaceUri, "title")) != null;
String title = e.getAttributeNS(EpubConstants.XLinkNamespaceUri, "title");
String ariaLabel = e.getAttribute("aria-label");
hasLabel = !Strings.isNullOrEmpty(title) || !Strings.isNullOrEmpty(ariaLabel);
}
}

Expand Down Expand Up @@ -866,7 +871,7 @@ else if (name.equals("a"))
report.message(MessageId.ACC_004, location().context("a"));
anchorNeedsText = false;
}
if ((inSvg || context.mimeType.equals("image/svg+xml")) && !hasTitle)
if ((inSvg || context.mimeType.equals("image/svg+xml")) && !hasLabel)
{
report.message(MessageId.ACC_011, location().context(e.getName()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ACC_007=Content Documents do not use "epub:type" attributes for semantic inflect
ACC_008=Navigation Document has no "landmarks nav" element.
ACC_009=MathML should either have an "alttext" attribute or "annotation-xml" child element.
ACC_010=Headings should not be used within blockquote and figure elements.
ACC_011=SVG hyperlinks should have a human-readable title (using the "title" child element or the "xlink:title" attribute).
ACC_011=SVG hyperlink has no accessible name
ACC_012=Table elements should include a caption element.
ACC_013=Content file contains at least one inline style declaration.
ACC_013_SUG=Inline styles are not compatible with accessibility settings and display personalization. Use CSS Styles instead.
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/org/w3c/epubcheck/test/AssertionSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ public void assertNoErrorsOrWarning()
assertThat("Unexpected warning", report.getAll(Severity.WARNING), is(emptyIterable()));
}

@Then("no( other) usage(s) are/is reported")
public void assertNoUsage()
{
assertThat("Unexpected usage", report.getAll(Severity.USAGE), is(emptyIterable()));
}

/*
* Common step definition for "is reported" and "is reported {int} times" see
* https://github.com/cucumber/cucumber-expressions/issues/166
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@ Feature: EPUB 3 — Content Documents — SVG
When checking document 'link-valid.svg'
Then no errors or warnings are reported

Scenario: Report SVG link without a title
When checking document 'link-no-title-error.svg'
Then warning ACC-011 is reported
Scenario: Report SVG link without a label as usage
Given the reporting level is set to usage
When checking document 'link-label-valid.svg'
Then usage ACC-011 is reported
And no other usages are reported
And no other errors or warnings are reported

Scenario: Verify that `image` elements can have an `xlink:href` URL pointing to a fragment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -961,12 +961,6 @@ Feature: EPUB 3 — Content Documents — XHTML
And the message contains 'element "foo" not allowed here'
And no other errors or warnings are reported

#TODO review if this warning is relevant
Scenario: Report an SVG link without a recommended title
When checking document 'svg-links-no-title-warning.xhtml'
Then warning ACC-011 is reported
And no other errors or warnings are reported

Scenario: Verify unprefixed HTML elements allowed inside prefixed `foreignObject`
When checking document 'svg-foreignObject-valid.xhtml'
Then no errors or warnings are reported
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

This file was deleted.

0 comments on commit 5903626

Please sign in to comment.