Skip to content

Commit

Permalink
Validate boundaries of tsv
Browse files Browse the repository at this point in the history
  • Loading branch information
dr0i committed Nov 21, 2023
1 parent ab656cb commit b68b58e
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public final class HelpPrinter {
private static final String PATH_TO_EXAMPLES = "../metafacture-documentation/linksAndExamples.tsv";
private static final Map<String, String[]> EXAMPLES_MAP = new HashMap<>();
private static final int COLUMN_TO_PG_EXAMPLE = 3;
private static final int REQUIRED_COLUMNS_OF_EXAMPLE = 2;
private static final int MAX_COLUMNS_OF_EXAMPLE = COLUMN_TO_PG_EXAMPLE;
private static final int MIN_COLUMNS_OF_EXAMPLE = 2;

private HelpPrinter() {
// no instances
Expand Down Expand Up @@ -126,9 +127,11 @@ private static <T> void describe(final String name, final ObjectFactory<T> facto
printSignature(out, moduleClass);

final String[] examplesEntry = EXAMPLES_MAP.get(name);
if (!EXAMPLES_MAP.isEmpty() && (examplesEntry == null || examplesEntry.length < REQUIRED_COLUMNS_OF_EXAMPLE)) {
if (!EXAMPLES_MAP.isEmpty() && (examplesEntry == null || examplesEntry.length < MIN_COLUMNS_OF_EXAMPLE ||
examplesEntry.length > MAX_COLUMNS_OF_EXAMPLE)) {
throw new MetafactureException(
"Failed to load build infos: tsv with links hasn't at least " + REQUIRED_COLUMNS_OF_EXAMPLE +
"Failed to load build infos: tsv with links hasn't at least " + MIN_COLUMNS_OF_EXAMPLE + " " +
"or exceeds the number of allowed columns (i.e. " + MAX_COLUMNS_OF_EXAMPLE + ")" +
" for the entry '" + name + "'");
}
if (examplesEntry != null && examplesEntry.length == COLUMN_TO_PG_EXAMPLE) {
Expand Down

0 comments on commit b68b58e

Please sign in to comment.