Skip to content
Open
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
14 changes: 13 additions & 1 deletion src/main/java/uk/ac/cam/cl/dtg/segue/etl/ContentIndexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -962,7 +963,9 @@ public void recordContentTypeSpecificError(final String sha, final Content conte
int sizeInKiloBytes = fileData.size() / 1024;
this.registerContentProblem(content, String.format("Image (%s) is %s kB and exceeds file size warning limit!",
f.getSrc(), sizeInKiloBytes), indexProblemCache);
} else if (f.getSrc().endsWith(".svg")) {
}

if (f.getSrc().endsWith(".svg") && null != fileData) {
// Check file contents for svg with either no defined width or a %-based width
String fileContents = fileData.toString();
Pattern pattern = Pattern.compile("(<svg[^>]*width\\s*=\\s*\"\\d+%\"[^>]*>|<svg(?![^>]*width)[^>]*>)\\n?");
Expand All @@ -974,6 +977,15 @@ public void recordContentTypeSpecificError(final String sha, final Content conte
);
}
}

Pattern badCharacters = Pattern.compile("[^a-zA-Z0-9-_.~/ ]");
Matcher badCharactersMatcher = badCharacters.matcher(f.getSrc());
if (badCharactersMatcher.find()) {
this.registerContentProblem(content, String.format("Filename '%s' contains illegal character '%s'.",
f.getSrc(), badCharactersMatcher.group()),
indexProblemCache
);
}
}

// check that there is some alt text.
Expand Down
Loading