@Test public void testWARCHeaderValueSanitise() { String[][] TESTS = new String[][]{ {"foo bar", "foo bar"}, {"<foo bar", "<foo bar"}, {"foo bar>", "foo bar>"}, {"<foo bar>", "foo bar"}, {"foo< >bar", "foo< >bar"}, {"<foo< >bar>", "foo< >bar"} }; for (String[] test: TESTS) { assertEquals("WARC-header value should be sanitised as expected for input '" + test[0] + "'", test[1], Normalisation.sanitiseWARCHeaderValue(test[0])); } }
public static String sanitiseWARCHeaderValue(String value) { if (value == null) { return null; } if (value.startsWith("<")) { if (value.endsWith(">")) { return value.substring(1, value.length()-1); } log.warn("sanitiseWARCHeaderValue: The value started with '<' but did not end in '>': '" + value + "'"); } else if (value.endsWith(">")) { log.warn("sanitiseWARCHeaderValue: The value ended with '>' but did not start with '<': '" + value + "'"); } return value; }
Normalisation { public static String sanitiseWARCHeaderValue(String value) { if (value == null) { return null; } if (value.startsWith("<")) { if (value.endsWith(">")) { return value.substring(1, value.length()-1); } log.warn("sanitiseWARCHeaderValue: The value started with '<' but did not end in '>': '" + value + "'"); } else if (value.endsWith(">")) { log.warn("sanitiseWARCHeaderValue: The value ended with '>' but did not start with '<': '" + value + "'"); } return value; } }
Normalisation { public static String sanitiseWARCHeaderValue(String value) { if (value == null) { return null; } if (value.startsWith("<")) { if (value.endsWith(">")) { return value.substring(1, value.length()-1); } log.warn("sanitiseWARCHeaderValue: The value started with '<' but did not end in '>': '" + value + "'"); } else if (value.endsWith(">")) { log.warn("sanitiseWARCHeaderValue: The value ended with '>' but did not start with '<': '" + value + "'"); } return value; }  }
Normalisation { public static String sanitiseWARCHeaderValue(String value) { if (value == null) { return null; } if (value.startsWith("<")) { if (value.endsWith(">")) { return value.substring(1, value.length()-1); } log.warn("sanitiseWARCHeaderValue: The value started with '<' but did not end in '>': '" + value + "'"); } else if (value.endsWith(">")) { log.warn("sanitiseWARCHeaderValue: The value ended with '>' but did not start with '<': '" + value + "'"); } return value; }  static String sanitiseWARCHeaderValue(String value); static String canonicaliseHost(String host); static String canonicaliseURL(String url); static String fixURLErrors(String url); static String resolveRelative(String url, String relative); static String resolveRelative(String url, String relative, boolean normalise); static String canonicaliseURL(String url, boolean allowHighOrder, boolean createUnambiguous); }
Normalisation { public static String sanitiseWARCHeaderValue(String value) { if (value == null) { return null; } if (value.startsWith("<")) { if (value.endsWith(">")) { return value.substring(1, value.length()-1); } log.warn("sanitiseWARCHeaderValue: The value started with '<' but did not end in '>': '" + value + "'"); } else if (value.endsWith(">")) { log.warn("sanitiseWARCHeaderValue: The value ended with '>' but did not start with '<': '" + value + "'"); } return value; }  static String sanitiseWARCHeaderValue(String value); static String canonicaliseHost(String host); static String canonicaliseURL(String url); static String fixURLErrors(String url); static String resolveRelative(String url, String relative); static String resolveRelative(String url, String relative, boolean normalise); static String canonicaliseURL(String url, boolean allowHighOrder, boolean createUnambiguous);  }