From b68b58e1567fb9441db4b151b36c3ccd304a54dd Mon Sep 17 00:00:00 2001 From: Pascal Christoph Date: Tue, 21 Nov 2023 13:48:40 +0100 Subject: [PATCH] Validate boundaries of tsv --- .../src/main/java/org/metafacture/flux/HelpPrinter.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/metafacture-flux/src/main/java/org/metafacture/flux/HelpPrinter.java b/metafacture-flux/src/main/java/org/metafacture/flux/HelpPrinter.java index 9fa9c397..a5a4620e 100644 --- a/metafacture-flux/src/main/java/org/metafacture/flux/HelpPrinter.java +++ b/metafacture-flux/src/main/java/org/metafacture/flux/HelpPrinter.java @@ -52,7 +52,8 @@ public final class HelpPrinter { private static final String PATH_TO_EXAMPLES = "../metafacture-documentation/linksAndExamples.tsv"; private static final Map 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 @@ -126,9 +127,11 @@ private static void describe(final String name, final ObjectFactory 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) {