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

feat: improve fallback detection checks #1436

Merged
merged 2 commits into from
Dec 6, 2022

Conversation

rdeltour
Copy link
Member

@rdeltour rdeltour commented Dec 5, 2022

This PR updates fallback-related checks and refactors the code used
for checking references to publication resources.

The following checks are introduced or updated:

  • RSC-032 (new): reports foreign resources with no fallback used in
    content documents. Replaces MED-001, MED-002, and CSS-010
  • MED-003 now reports when an img element child of a picture element
    is not a core media type.
  • MED-001 is suppressed. It was used to report a video poster attribute
    did not reference a core image media type. It is now reported as RSC-032.
  • MED-002 is suppressed. It was used to report HTML elements referencing
    foreign resources without fallback. It is now reported as RSC-032.
  • CSS-010 is suppressed. It was used to report references to foreign
    stylesheets with no fallback. It is now reported as RSC-032.
  • OPF_040 is now reported when the fallback attribute of a package
    document item element does not points to an existing ID. This was
    previously implemented as a Schematron check (RSC-005) in EPUB 3.x.
  • OPF-013 is now a warning. It is reported when a MIME type declared
    inline in content (for instance with an HTML type attribute) does
    not match the MIME type declared in the package document.

The code is refactored as follows:

  • the reference/resource registry functionality of the XRefChecker
    class is extracted to new top-level classes in the (new) package
    org.w3c.epubcheck.references.
    • Resource represents a publication resource
    • ResourceRegistry is a registry of Resource instances
    • Reference represents a reference (URL) used anywhere in content
    • ReferenceRegistry is a registry of Reference instances
    • XRefChecker is renamed to ResourceReferencesChecker.
    • ValidationContext contains optional references to ResourceRegistry
      and ReferenceRegistry.
    • fallback chain resolution is now done in a new FallbackChainResolver
      class, when building OPFItem instances from the builders created
      when parsing the package document.
    • XMLHandler has convenience methods used to register references
      to the ReferenceRegistry.

Fix #1304, Fix #1298.

This allows private data to store information for different purposes without risks of conflicts.
This commit updates fallback-related checks and refactors the code used
for checking references to publication resources.

The following checks are introduced or updated:

- `RSC-032` (new): reports foreign resources with no fallback used in
  content documents. Replaces `MED-001`, `MED-002`, and `CSS-010`
- `MED-003` now reports when an `img` element child of a `picture` element
  is not a core media type.
- `MED-001` is suppressed. It was used to report a video `poster` attribute
  did not reference a core image media type. It is now reported as `RSC-032`.
- `MED-002` is suppressed. It was used to report HTML elements referencing
  foreign resources without fallback. It is now reported as `RSC-032`.
- `CSS-010` is suppressed. It was used to report references to foreign
  stylesheets with no fallback. It is now reported as `RSC-032`.
- `OPF_040` is now reported when the `fallback` attribute of a package
  document `item` element does not points to an existing ID. This was
  previously implemented as a Schematron check (`RSC-005`) in EPUB 3.x.
- `OPF-013` is now a warning. It is reported when a MIME type declared
  inline in content (for instance with an HTML `type` attribute) does
  not match the MIME type declared in the package document.

The code is refactored as follows:
- the reference/resource registry functionality of the `XRefChecker`
  class is extracted to new top-level classes in the (new) package
  `org.w3c.epubcheck.references`.
  - `Resource` represents a publication resource
  - `ResourceRegistry` is a registry of `Resource` instances
  - `Reference` represents a reference (URL) used anywhere in content
  - `ReferenceRegistry` is a registry of `Reference` instances
  - `XRefChecker` is renamed to `ResourceReferencesChecker`.
  - `ValidationContext` contains optional references to `ResourceRegistry`
    and `ReferenceRegistry`.
  - fallback chain resolution is now done in a new `FallbackChainResolver`
    class, when building `OPFItem` instances from the builders created
    when parsing the package document.
  - `XMLHandler` has convenience methods used to register references
    to the `ReferenceRegistry`.

Fix #1304, Fix #1298.
@rdeltour rdeltour added this to the v5.0.0-beta milestone Dec 5, 2022
@rdeltour rdeltour self-assigned this Dec 5, 2022
Base automatically changed from feat/remove-bindings-checks to release/v5.0.0 December 6, 2022 14:55
@rdeltour rdeltour merged commit 545b7f7 into release/v5.0.0 Dec 6, 2022
@rdeltour rdeltour deleted the feat/improve-fallback-checks branch December 6, 2022 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants