Skip to content

Commit

Permalink
Fix image default scope
Browse files Browse the repository at this point in the history
Per DITA 1.3 spec 3.12.13.11 "The @scope attribute"
Fixes #4032

Signed-off-by: Jarno Elovirta <jarno@elovirta.com>
  • Loading branch information
jelovirt committed Nov 6, 2022
1 parent a5c87cf commit 07ec1cd
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/main/java/org/dita/dost/reader/GenListModuleReader.java
Expand Up @@ -567,7 +567,19 @@ private void parseAttribute(final Attributes atts, final String attrName) throws
}

final String attrClass = atts.getValue(ATTRIBUTE_NAME_CLASS);
final String attrScope = atts.getValue(ATTRIBUTE_NAME_SCOPE);
String attrScope = atts.getValue(ATTRIBUTE_NAME_SCOPE);
if (attrScope == null && ATTRIBUTE_NAME_HREF.equals(attrName) && attrValue.isAbsolute()) {
switch (attrValue.getScheme()) {
case "http":
case "https":
case "ftp":
case "ftps":
case "sftp":
case "mailto":
attrScope = ATTR_SCOPE_VALUE_EXTERNAL;
break;
}
}

// external resource is filtered here.
if (ATTR_SCOPE_VALUE_EXTERNAL.equals(attrScope) || ATTR_SCOPE_VALUE_PEER.equals(attrScope)
Expand Down
42 changes: 40 additions & 2 deletions src/test/java/org/dita/dost/reader/TestGenListModuleReader.java
Expand Up @@ -36,8 +36,7 @@
import java.util.stream.Stream;

import static java.util.Collections.emptySet;
import static org.dita.dost.util.Constants.FEATURE_VALIDATION;
import static org.dita.dost.util.Constants.FEATURE_VALIDATION_SCHEMA;
import static org.dita.dost.util.Constants.*;
import static org.dita.dost.util.URLUtils.stripFragment;
import static org.junit.Assert.*;

Expand Down Expand Up @@ -87,6 +86,45 @@ public void startElement() throws SAXException {
.build());
}

@Test
public void startElement_localImage() throws SAXException {
reader.startDocument();
reader.startElement("", "image", "image", new AttributesBuilder()
.add(ATTRIBUTE_NAME_CLASS, TOPIC_IMAGE.toString())
.add(ATTRIBUTE_NAME_HREF, "image.png")
.build());
assertEquals(1, reader.getNonConrefCopytoTargets().size());
assertEquals(ATTR_FORMAT_VALUE_IMAGE, reader.getNonConrefCopytoTargets().iterator().next().format);
assertEquals(
inputDir.toURI().resolve("image.png"),
reader.getNonConrefCopytoTargets().iterator().next().filename);
assertEquals(1, reader.getNonTopicrefReferenceSet().size());
assertEquals(
inputDir.toURI().resolve("image.png"),
reader.getNonTopicrefReferenceSet().iterator().next());
}

@Test
public void startElement_externalImage_withScope() throws SAXException {
reader.startDocument();
reader.startElement("", "image", "image", new AttributesBuilder()
.add(ATTRIBUTE_NAME_CLASS, TOPIC_IMAGE.toString())
.add(ATTRIBUTE_NAME_HREF, "http://example.com/image.png")
.add(ATTRIBUTE_NAME_SCOPE, ATTR_SCOPE_VALUE_EXTERNAL)
.build());
assertTrue(reader.getNonConrefCopytoTargets().isEmpty());
}

@Test
public void startElement_externalImage_withoutScope() throws SAXException {
reader.startDocument();
reader.startElement("", "image", "image", new AttributesBuilder()
.add(ATTRIBUTE_NAME_CLASS, TOPIC_IMAGE.toString())
.add(ATTRIBUTE_NAME_HREF, "http://example.com/image.png")
.build());
assertTrue(reader.getNonConrefCopytoTargets().isEmpty());
}

@Test
public void testParse() throws Exception {
final File rootFile = new File(inputDir, "root-map-01.ditamap");
Expand Down

0 comments on commit 07ec1cd

Please sign in to comment.