id
stringlengths
33
68
content
stringlengths
657
500k
max_stars_repo_path
stringlengths
118
258
gitbug-java_data_Moderocky-ByteSkript.json_1
diff --git a/src/main/java/org/byteskript/skript/compiler/DebugSkriptCompiler.java b/src/main/java/org/byteskript/skript/compiler/DebugSkriptCompiler.java index fec865f..2864b22 100644 --- a/src/main/java/org/byteskript/skript/compiler/DebugSkriptCompiler.java +++ b/src/main/java/org/byteskript/skript/compiler/DebugSkriptCompiler.java @@ -41,15 +41,15 @@ public class DebugSkriptCompiler extends SimpleSkriptCompiler { public PostCompileClass[] compile(InputStream stream, Type path) { this.stream.print("\n"); this.stream.print("--" + path.internalName()); - this.stream.print("\n"); + this.stream.print("\n\n"); return super.compile(stream, path); } @Override public PostCompileClass[] compile(String source, Type path) { - this.stream.print("\n\n"); - this.stream.print("--" + path.internalName()); this.stream.print("\n"); + this.stream.print("--" + path.internalName()); + this.stream.print("\n\n"); return super.compile(source, path); } @@ -59,9 +59,8 @@ public class DebugSkriptCompiler extends SimpleSkriptCompiler { } protected void debug(ElementTree tree, FileContext context) { - this.stream.print("\n"); for (int i = 0; i < context.lineIndent; i++) this.stream.print("\t"); - this.stream.print(tree.toString(context)); + this.stream.println(tree.toString(context)); } } diff --git a/src/test/java/org/byteskript/skript/test/SyntaxTreeTest.java b/src/test/java/org/byteskript/skript/test/SyntaxTreeTest.java index a882c7d..9da5a76 100644 --- a/src/test/java/org/byteskript/skript/test/SyntaxTreeTest.java +++ b/src/test/java/org/byteskript/skript/test/SyntaxTreeTest.java @@ -47,7 +47,6 @@ public class SyntaxTreeTest extends SkriptTest { """, new Type("test")); assert stream.toString().equals(""" - --test MemberDictionary(): @@ -68,7 +67,8 @@ public class SyntaxTreeTest extends SkriptTest { EventLoad(): EntryTriggerSection(): - EffectPrint(StringLiteral("Foo"))""") : '"' + stream.toString() + '"'; + EffectPrint(StringLiteral("Foo")) + """) : '"' + stream.toString() + '"'; } }
https://github.com/Moderocky/ByteSkript.gitdiff --git a/src/main/java/org/byteskript/skript/compiler/DebugSkriptCompiler.java b/src/main/java/org/byteskript/skript/compiler/DebugSkriptCompiler.java
gitbug-java_data_aws-event-ruler.json_1
diff --git a/src/main/software/amazon/event/ruler/JsonRuleCompiler.java b/src/main/software/amazon/event/ruler/JsonRuleCompiler.java index c6157f0..d76e22a 100644 --- a/src/main/software/amazon/event/ruler/JsonRuleCompiler.java +++ b/src/main/software/amazon/event/ruler/JsonRuleCompiler.java @@ -4,6 +4,8 @@ import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; +import software.amazon.event.ruler.input.ParseException; + import java.io.IOException; import java.io.InputStream; import java.io.Reader; @@ -15,6 +17,8 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; +import static software.amazon.event.ruler.input.DefaultParser.getParser; + /** * Represents a updated compiler comparing to RuleCompiler class, it parses a rule described by a JSON string into * a list of Map which is composed of field Patterns, each Map represents one dedicated match branch in the rule. @@ -494,7 +498,13 @@ public class JsonRuleCompiler { barf(parser, "wildcard match pattern must be a string"); } final String parserText = parser.getText(); - final Patterns pattern = Patterns.wildcardMatch('"' + parserText + '"'); + String value = '"' + parserText + '"'; + try { + getParser().parse(MatchType.WILDCARD, value); + } catch (ParseException e) { + barf(parser, e.getLocalizedMessage()); + } + final Patterns pattern = Patterns.wildcardMatch(value); if (parser.nextToken() != JsonToken.END_OBJECT) { barf(parser, "Only one key allowed in match expression"); } diff --git a/src/main/software/amazon/event/ruler/RuleCompiler.java b/src/main/software/amazon/event/ruler/RuleCompiler.java index 872303d..01cce52 100644 --- a/src/main/software/amazon/event/ruler/RuleCompiler.java +++ b/src/main/software/amazon/event/ruler/RuleCompiler.java @@ -16,6 +16,9 @@ import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; +import software.amazon.event.ruler.input.ParseException; + +import static software.amazon.event.ruler.input.DefaultParser.getParser; /** * Compiles Rules, expressed in JSON, for use in Ruler. @@ -393,7 +396,13 @@ public final class RuleCompiler { barf(parser, "wildcard match pattern must be a string"); } final String parserText = parser.getText(); - final Patterns pattern = Patterns.wildcardMatch('"' + parserText + '"'); + String value = '"' + parserText + '"'; + try { + getParser().parse(MatchType.WILDCARD, value); + } catch (ParseException e) { + barf(parser, e.getLocalizedMessage()); + } + final Patterns pattern = Patterns.wildcardMatch(value); if (parser.nextToken() != JsonToken.END_OBJECT) { barf(parser, "Only one key allowed in match expression"); } diff --git a/src/test/software/amazon/event/ruler/JsonRuleCompilerTest.java b/src/test/software/amazon/event/ruler/JsonRuleCompilerTest.java index 42b04c0..f8b14c4 100644 --- a/src/test/software/amazon/event/ruler/JsonRuleCompilerTest.java +++ b/src/test/software/amazon/event/ruler/JsonRuleCompilerTest.java @@ -3,6 +3,7 @@ package software.amazon.event.ruler; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonNode; import java.io.ByteArrayInputStream; +import java.io.IOException; import java.io.InputStream; import java.io.StringReader; import java.nio.charset.StandardCharsets; @@ -14,6 +15,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; public class JsonRuleCompilerTest { @@ -535,4 +537,27 @@ public class JsonRuleCompilerTest { assertTrue(machine.isEmpty()); } + @Test + public void testWildcardConsecutiveWildcards() throws IOException { + try { + JsonRuleCompiler.compile("{\"key\": [{\"wildcard\": \"abc**def\"}]}"); + fail("Expected JSONParseException"); + } catch (JsonParseException e) { + assertEquals("Consecutive wildcard characters at pos 4\n" + + " at [Source: (String)\"{\"key\": [{\"wildcard\": \"abc**def\"}]}\"; line: 1, column: 33]", + e.getMessage()); + } + } + + @Test + public void testWildcardInvalidEscapeCharacter() throws IOException { + try { + JsonRuleCompiler.compile("{\"key\": [{\"wildcard\": \"a*c\\def\"}]}"); + fail("Expected JSONParseException"); + } catch (JsonParseException e) { + assertEquals("Unrecognized character escape 'd' (code 100)\n" + + " at [Source: (String)\"{\"key\": [{\"wildcard\": \"a*c\\def\"}]}\"; line: 1, column: 29]", + e.getMessage()); + } + } } diff --git a/src/test/software/amazon/event/ruler/RuleCompilerTest.java b/src/test/software/amazon/event/ruler/RuleCompilerTest.java index 8d55f80..d569ede 100644 --- a/src/test/software/amazon/event/ruler/RuleCompilerTest.java +++ b/src/test/software/amazon/event/ruler/RuleCompilerTest.java @@ -1,6 +1,8 @@ package software.amazon.event.ruler; +import com.fasterxml.jackson.core.JsonParseException; import java.io.ByteArrayInputStream; +import java.io.IOException; import java.io.InputStream; import java.io.StringReader; import java.nio.charset.StandardCharsets; @@ -534,6 +536,30 @@ public class RuleCompilerTest { } + @Test + public void testWildcardConsecutiveWildcards() throws IOException { + try { + RuleCompiler.compile("{\"key\": [{\"wildcard\": \"abc**def\"}]}"); + fail("Expected JSONParseException"); + } catch (JsonParseException e) { + assertEquals("Consecutive wildcard characters at pos 4\n" + + " at [Source: (String)\"{\"key\": [{\"wildcard\": \"abc**def\"}]}\"; line: 1, column: 33]", + e.getMessage()); + } + } + + @Test + public void testWildcardInvalidEscapeCharacter() throws IOException { + try { + RuleCompiler.compile("{\"key\": [{\"wildcard\": \"a*c\\def\"}]}"); + fail("Expected JSONParseException"); + } catch (JsonParseException e) { + assertEquals("Unrecognized character escape 'd' (code 100)\n" + + " at [Source: (String)\"{\"key\": [{\"wildcard\": \"a*c\\def\"}]}\"; line: 1, column: 29]", + e.getMessage()); + } + } + private void multiThreadedTestHelper(List<String> rules, List<String[]> events, int numMatchesPerEvent) throws Exception {
https://github.com/aws/event-ruler.gitdiff --git a/src/main/software/amazon/event/ruler/JsonRuleCompiler.java b/src/main/software/amazon/event/ruler/JsonRuleCompiler.java
gitbug-java_data_BrightSpots-rcv.json_1
diff --git a/src/main/java/network/brightspots/rcv/Logger.java b/src/main/java/network/brightspots/rcv/Logger.java index 78d7b1e..f0a5077 100644 --- a/src/main/java/network/brightspots/rcv/Logger.java +++ b/src/main/java/network/brightspots/rcv/Logger.java @@ -32,6 +32,7 @@ package network.brightspots.rcv; +import java.io.File; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; @@ -59,6 +60,7 @@ class Logger { private static final java.util.logging.Formatter formatter = new LogFormatter(); private static java.util.logging.Logger logger; private static java.util.logging.FileHandler tabulationHandler; + private static String tabulationLogPattern; static void setup() { logger = java.util.logging.Logger.getLogger(""); @@ -95,7 +97,7 @@ class Logger { throws IOException { // log file name is: outputFolder + timestamp + log index // FileHandler requires % to be encoded as %%. %g is the log index - String tabulationLogPattern = + tabulationLogPattern = Paths.get(outputFolder.replace("%", "%%"), String.format("%s_audit_%%g.log", timestampString)) .toAbsolutePath() @@ -116,6 +118,19 @@ class Logger { tabulationHandler.flush(); tabulationHandler.close(); logger.removeHandler(tabulationHandler); + + int index = 0; + while (true) { + File file = new File(tabulationLogPattern.replace("%g", String.valueOf(index))); + if (!file.exists()) { + break; + } + boolean readOnlySucceeded = file.setReadOnly(); + if (!readOnlySucceeded) { + warning("Failed to set file to read-only: %s", file.getAbsolutePath()); + } + index++; + } } static void fine(String message, Object... obj) { diff --git a/src/main/java/network/brightspots/rcv/ResultsWriter.java b/src/main/java/network/brightspots/rcv/ResultsWriter.java index 16d115b..b97ded9 100644 --- a/src/main/java/network/brightspots/rcv/ResultsWriter.java +++ b/src/main/java/network/brightspots/rcv/ResultsWriter.java @@ -116,6 +116,10 @@ class ResultsWriter { try { jsonWriter.writeValue(outFile, json); + boolean readOnlySucceeded = outFile.setReadOnly(); + if (!readOnlySucceeded) { + Logger.warning("Failed to set file to read-only: %s", outFile.getAbsolutePath()); + } } catch (IOException exception) { Logger.severe( "Error writing to JSON file: %s\n%s\nPlease check the file path and permissions!", @@ -386,6 +390,12 @@ class ResultsWriter { try { csvPrinter.flush(); csvPrinter.close(); + + File file = new File(csvPath); + boolean readOnlySucceeded = file.setReadOnly(); + if (!readOnlySucceeded) { + Logger.warning("Failed to set file to read-only: %s", file.getAbsolutePath()); + } } catch (IOException exception) { Logger.severe("Error saving file: %s\n%s", outputPath, exception); throw exception; @@ -554,6 +564,12 @@ class ResultsWriter { csvPrinter.close(); filesWritten.add(outputPath.toString()); Logger.info("Successfully wrote: %s", outputPath.toString()); + + File file = new File(outputPath.toString()); + boolean readOnlySucceeded = file.setReadOnly(); + if (!readOnlySucceeded) { + Logger.warning("Failed to set file to read-only: %s", file.getAbsolutePath()); + } } } catch (IOException exception) { Logger.severe( diff --git a/src/test/java/network/brightspots/rcv/TabulatorTests.java b/src/test/java/network/brightspots/rcv/TabulatorTests.java index 2905c66..92d0646 100644 --- a/src/test/java/network/brightspots/rcv/TabulatorTests.java +++ b/src/test/java/network/brightspots/rcv/TabulatorTests.java @@ -144,6 +144,15 @@ class TabulatorTests { for (File file : files) { if (!file.isDirectory()) { try { + // Every ephemeral file must be set to read-only on close, including audit logs + assertFalse( + file.canWrite(), + "File must be set to read-only: %s".formatted(file.getAbsolutePath())); + // Then set it writeable so it can be deleted + boolean writeableSucceeded = file.setWritable(true); + if (!writeableSucceeded) { + Logger.warning("Failed to set file to writeable: %s", file.getAbsolutePath()); + } Files.delete(file.toPath()); } catch (IOException exception) { Logger.severe("Error deleting file: %s\n%s", file.getAbsolutePath(), exception);
https://github.com/BrightSpots/rcv.gitdiff --git a/src/main/java/network/brightspots/rcv/Logger.java b/src/main/java/network/brightspots/rcv/Logger.java
gitbug-java_data_BrightSpots-rcv.json_2
diff --git a/src/main/java/network/brightspots/rcv/ResultsWriter.java b/src/main/java/network/brightspots/rcv/ResultsWriter.java index c80bc61..5243d6c 100644 --- a/src/main/java/network/brightspots/rcv/ResultsWriter.java +++ b/src/main/java/network/brightspots/rcv/ResultsWriter.java @@ -375,10 +375,10 @@ class ResultsWriter { csvPrinter.println(); Pair<String, StatusForRound>[] statusesToPrint = new Pair[]{ - new Pair<>("by Overvotes", StatusForRound.INACTIVE_BY_OVERVOTE), - new Pair<>("by Skipped Rankings", StatusForRound.INACTIVE_BY_SKIPPED_RANKING), - new Pair<>("by Exhausted Choices", StatusForRound.INACTIVE_BY_EXHAUSTED_CHOICES), - new Pair<>("by Repeated Rankings", StatusForRound.INACTIVE_BY_REPEATED_RANKING) + new Pair<>("Overvotes", StatusForRound.INACTIVE_BY_OVERVOTE), + new Pair<>("Skipped Rankings", StatusForRound.INACTIVE_BY_SKIPPED_RANKING), + new Pair<>("Exhausted Choices", StatusForRound.INACTIVE_BY_EXHAUSTED_CHOICES), + new Pair<>("Repeated Rankings", StatusForRound.INACTIVE_BY_REPEATED_RANKING) }; for (Pair<String, StatusForRound> statusToPrint : statusesToPrint) { @@ -387,6 +387,11 @@ class ResultsWriter { StatusForRound status = statusToPrint.getValue(); BigDecimal thisRoundInactive = roundTallies.get(round).getBallotStatusTally(status); csvPrinter.print(thisRoundInactive); + + // Don't display percentage of inactive ballots + csvPrinter.print(""); + + // Do display transfer of inactive ballots if (round != numRounds) { BigDecimal nextRoundInactive = roundTallies.get(round + 1).getBallotStatusTally(status); BigDecimal diff = nextRoundInactive.subtract(thisRoundInactive); @@ -394,9 +399,6 @@ class ResultsWriter { } else { csvPrinter.print(0); } - - // Don't display percentage of inactive ballots - csvPrinter.print(""); } csvPrinter.println(); } @@ -411,6 +413,10 @@ class ResultsWriter { BigDecimal thisRoundInactive = roundTallies.get(round).numInactiveBallots(); csvPrinter.print(thisRoundInactive.subtract(numUndervotes)); + // Don't display percentage of inactive ballots + csvPrinter.print(""); + + // Do display transfer of inactive ballots if (round != numRounds) { // Note: we don't need to subtract num undervotes here since we'd be subtracting the // same value from both sides of the equation, so it cancels out. @@ -420,9 +426,6 @@ class ResultsWriter { } else { csvPrinter.print(0); } - - // Don't display percentage of inactive ballots - csvPrinter.print(""); } csvPrinter.println(); diff --git a/src/test/resources/network/brightspots/rcv/test_data/2013_minneapolis_mayor/2013_minneapolis_mayor_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/2013_minneapolis_mayor/2013_minneapolis_mayor_expected_summary.csv index b377ba1..9694ce8 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/2013_minneapolis_mayor/2013_minneapolis_mayor_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/2013_minneapolis_mayor/2013_minneapolis_mayor_expected_summary.csv @@ -56,8 +56,8 @@ JOHN CHARLES WILSON,37,0.04%,1,38,0.04%,-38,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0, Undeclared Write-ins,117,0.14%,-117,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 Active Ballots,79312,,,79275,,,79269,,,79264,,,79253,,,79243,,,79226,,,79214,,,79197,,,79164,,,79135,,,79102,,,79065,,,79043,,,79003,,,78952,,,78923,,,78898,,,78826,,,78772,,,78716,,,78617,,,78493,,,78223,,,78081,,,77960,,,77451,,,77081,,,76623,,,76323,,,75590,,,73619,,,63794,, Current Round Threshold,39657,,,39638,,,39635,,,39633,,,39627,,,39622,,,39614,,,39608,,,39599,,,39583,,,39568,,,39552,,,39533,,,39522,,,39502,,,39477,,,39462,,,39450,,,39414,,,39387,,,39359,,,39309,,,39247,,,39112,,,39041,,,38981,,,38726,,,38541,,,38312,,,38162,,,37796,,,36810,,,31898,, -Inactive Ballots by by Overvotes,103,1,,104,0,,104,0,,104,0,,104,0,,104,0,,104,0,,104,0,,104,1,,105,1,,106,1,,107,0,,107,0,,107,0,,107,0,,107,0,,107,0,,107,0,,107,0,,107,0,,107,1,,108,1,,109,1,,110,0,,110,0,,110,1,,111,1,,112,2,,114,1,,115,2,,117,6,,123,17,,140,0, -Inactive Ballots by by Skipped Rankings,47,0,,47,0,,47,0,,47,0,,47,0,,47,0,,47,0,,47,0,,47,0,,47,0,,47,0,,47,0,,47,0,,47,0,,47,0,,47,0,,47,0,,47,0,,47,0,,47,0,,47,0,,47,0,,47,0,,47,0,,47,0,,47,0,,47,0,,47,0,,47,0,,47,0,,47,0,,47,0,,47,0, -Inactive Ballots by by Exhausted Choices,0,18,,18,0,,18,1,,19,1,,20,4,,24,5,,29,5,,34,2,,36,15,,51,14,,65,15,,80,11,,91,16,,107,27,,134,21,,155,21,,176,19,,195,28,,223,47,,270,46,,316,89,,405,101,,506,161,,667,100,,767,95,,862,306,,1168,336,,1504,261,,1765,236,,2001,535,,2536,1406,,3942,7827,,11769,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,150,37,,187,6,,193,5,,198,11,,209,10,,219,17,,236,12,,248,17,,265,33,,298,29,,327,33,,360,37,,397,22,,419,40,,459,51,,510,29,,539,25,,564,72,,636,54,,690,56,,746,99,,845,124,,969,270,,1239,142,,1381,121,,1502,509,,2011,370,,2381,458,,2839,300,,3139,733,,3872,1971,,5843,9825,,15668,0, +Inactive Ballots by Overvotes,103,,1,104,,0,104,,0,104,,0,104,,0,104,,0,104,,0,104,,0,104,,1,105,,1,106,,1,107,,0,107,,0,107,,0,107,,0,107,,0,107,,0,107,,0,107,,0,107,,0,107,,1,108,,1,109,,1,110,,0,110,,0,110,,1,111,,1,112,,2,114,,1,115,,2,117,,6,123,,17,140,,0 +Inactive Ballots by Skipped Rankings,47,,0,47,,0,47,,0,47,,0,47,,0,47,,0,47,,0,47,,0,47,,0,47,,0,47,,0,47,,0,47,,0,47,,0,47,,0,47,,0,47,,0,47,,0,47,,0,47,,0,47,,0,47,,0,47,,0,47,,0,47,,0,47,,0,47,,0,47,,0,47,,0,47,,0,47,,0,47,,0,47,,0 +Inactive Ballots by Exhausted Choices,0,,18,18,,0,18,,1,19,,1,20,,4,24,,5,29,,5,34,,2,36,,15,51,,14,65,,15,80,,11,91,,16,107,,27,134,,21,155,,21,176,,19,195,,28,223,,47,270,,46,316,,89,405,,101,506,,161,667,,100,767,,95,862,,306,1168,,336,1504,,261,1765,,236,2001,,535,2536,,1406,3942,,7827,11769,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,150,,37,187,,6,193,,5,198,,11,209,,10,219,,17,236,,12,248,,17,265,,33,298,,29,327,,33,360,,37,397,,22,419,,40,459,,51,510,,29,539,,25,564,,72,636,,54,690,,56,746,,99,845,,124,969,,270,1239,,142,1381,,121,1502,,509,2011,,370,2381,,458,2839,,300,3139,,733,3872,,1971,5843,,9825,15668,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/2013_minneapolis_mayor_scale/2013_minneapolis_mayor_scale_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/2013_minneapolis_mayor_scale/2013_minneapolis_mayor_scale_expected_summary.csv index 17f95ef..6b2a87d 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/2013_minneapolis_mayor_scale/2013_minneapolis_mayor_scale_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/2013_minneapolis_mayor_scale/2013_minneapolis_mayor_scale_expected_summary.csv @@ -56,8 +56,8 @@ JOHN CHARLES WILSON,481,0.04%,13,494,0.04%,-494,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0 Undeclared Write-ins,1521,0.14%,-1521,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 Active Ballots,1031056,,,1030575,,,1030497,,,1030432,,,1030289,,,1030159,,,1029938,,,1029782,,,1029561,,,1029132,,,1028755,,,1028326,,,1027845,,,1027559,,,1027039,,,1026376,,,1025999,,,1025674,,,1024738,,,1024036,,,1023308,,,1022021,,,1020409,,,1016899,,,1015053,,,1013480,,,1006863,,,1002053,,,996099,,,992199,,,982670,,,957047,,,829322,, Current Round Threshold,515529,,,515288,,,515249,,,515217,,,515145,,,515080,,,514970,,,514892,,,514781,,,514567,,,514378,,,514164,,,513923,,,513780,,,513520,,,513189,,,513000,,,512838,,,512370,,,512019,,,511655,,,511011,,,510205,,,508450,,,507527,,,506741,,,503432,,,501027,,,498050,,,496100,,,491336,,,478524,,,414662,, -Inactive Ballots by by Overvotes,1339,13,,1352,0,,1352,0,,1352,0,,1352,0,,1352,0,,1352,0,,1352,0,,1352,13,,1365,13,,1378,13,,1391,0,,1391,0,,1391,0,,1391,0,,1391,0,,1391,0,,1391,0,,1391,0,,1391,0,,1391,13,,1404,13,,1417,13,,1430,0,,1430,0,,1430,13,,1443,13,,1456,26,,1482,13,,1495,26,,1521,78,,1599,221,,1820,0, -Inactive Ballots by by Skipped Rankings,611,0,,611,0,,611,0,,611,0,,611,0,,611,0,,611,0,,611,0,,611,0,,611,0,,611,0,,611,0,,611,0,,611,0,,611,0,,611,0,,611,0,,611,0,,611,0,,611,0,,611,0,,611,0,,611,0,,611,0,,611,0,,611,0,,611,0,,611,0,,611,0,,611,0,,611,0,,611,0,,611,0, -Inactive Ballots by by Exhausted Choices,0,234,,234,0,,234,13,,247,13,,260,52,,312,65,,377,65,,442,26,,468,195,,663,182,,845,195,,1040,143,,1183,208,,1391,351,,1742,273,,2015,273,,2288,247,,2535,364,,2899,611,,3510,598,,4108,1157,,5265,1313,,6578,2093,,8671,1300,,9971,1235,,11206,3978,,15184,4368,,19552,3393,,22945,3068,,26013,6955,,32968,18278,,51246,101751,,152997,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,1950,481,,2431,78,,2509,65,,2574,143,,2717,130,,2847,221,,3068,156,,3224,221,,3445,429,,3874,377,,4251,429,,4680,481,,5161,286,,5447,520,,5967,663,,6630,377,,7007,325,,7332,936,,8268,702,,8970,728,,9698,1287,,10985,1612,,12597,3510,,16107,1846,,17953,1573,,19526,6617,,26143,4810,,30953,5954,,36907,3900,,40807,9529,,50336,25623,,75959,127725,,203684,0, +Inactive Ballots by Overvotes,1339,,13,1352,,0,1352,,0,1352,,0,1352,,0,1352,,0,1352,,0,1352,,0,1352,,13,1365,,13,1378,,13,1391,,0,1391,,0,1391,,0,1391,,0,1391,,0,1391,,0,1391,,0,1391,,0,1391,,0,1391,,13,1404,,13,1417,,13,1430,,0,1430,,0,1430,,13,1443,,13,1456,,26,1482,,13,1495,,26,1521,,78,1599,,221,1820,,0 +Inactive Ballots by Skipped Rankings,611,,0,611,,0,611,,0,611,,0,611,,0,611,,0,611,,0,611,,0,611,,0,611,,0,611,,0,611,,0,611,,0,611,,0,611,,0,611,,0,611,,0,611,,0,611,,0,611,,0,611,,0,611,,0,611,,0,611,,0,611,,0,611,,0,611,,0,611,,0,611,,0,611,,0,611,,0,611,,0,611,,0 +Inactive Ballots by Exhausted Choices,0,,234,234,,0,234,,13,247,,13,260,,52,312,,65,377,,65,442,,26,468,,195,663,,182,845,,195,1040,,143,1183,,208,1391,,351,1742,,273,2015,,273,2288,,247,2535,,364,2899,,611,3510,,598,4108,,1157,5265,,1313,6578,,2093,8671,,1300,9971,,1235,11206,,3978,15184,,4368,19552,,3393,22945,,3068,26013,,6955,32968,,18278,51246,,101751,152997,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,1950,,481,2431,,78,2509,,65,2574,,143,2717,,130,2847,,221,3068,,156,3224,,221,3445,,429,3874,,377,4251,,429,4680,,481,5161,,286,5447,,520,5967,,663,6630,,377,7007,,325,7332,,936,8268,,702,8970,,728,9698,,1287,10985,,1612,12597,,3510,16107,,1846,17953,,1573,19526,,6617,26143,,4810,30953,,5954,36907,,3900,40807,,9529,50336,,25623,75959,,127725,203684,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/2013_minneapolis_park/2013_minneapolis_park_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/2013_minneapolis_park/2013_minneapolis_park_expected_summary.csv index e493140..53359ed 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/2013_minneapolis_park/2013_minneapolis_park_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/2013_minneapolis_park/2013_minneapolis_park_expected_summary.csv @@ -31,9 +31,9 @@ CASPER HILL,1280,2.15%,4,1284,2.16%,-1284,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0, Undeclared Write-ins,342,0.57%,-342,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,,0 Active Ballots,59463,,,59174,,,58876,,,44010.0000,,,42995.0000,,,41914.0000,,,40009.0000,,,36612.0000,,,33552.0000,,,27289.0000,,,0,, Current Round Threshold,14866,,,14866,,,14866,,,14866,,,14866,,,14866,,,14866,,,14866,,,14866,,,14866,,,14866,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,67,289,,356,298,,654,0.0000,,654.0000,1015.0000,,1669.0000,1081.0000,,2750.0000,1905.0000,,4655.0000,3397.0000,,8052.0000,3060.0000,,11112.0000,6263.0000,,17375.0000,177.5192,,17552.5192,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,67,289,,356,298,,654,0.0000,,654.0000,1015.0000,,1669.0000,1081.0000,,2750.0000,1905.0000,,4655.0000,3397.0000,,8052.0000,3060.0000,,11112.0000,6263.0000,,17375.0000,177.5192,,17552.5192,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,67,,289,356,,298,654,,0.0000,654.0000,,1015.0000,1669.0000,,1081.0000,2750.0000,,1905.0000,4655.0000,,3397.0000,8052.0000,,3060.0000,11112.0000,,6263.0000,17375.0000,,177.5192,17552.5192,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,67,,289,356,,298,654,,0.0000,654.0000,,1015.0000,1669.0000,,1081.0000,2750.0000,,1905.0000,4655.0000,,3397.0000,8052.0000,,3060.0000,11112.0000,,6263.0000,17375.0000,,177.5192,17552.5192,,0 Residual surplus,0,,,0,,,0,,,0,,,0,,,0,,,0,,,0,,,0,,,0,,,0.4808,, diff --git a/src/test/resources/network/brightspots/rcv/test_data/2013_minneapolis_park_bottoms_up/2013_minneapolis_park_bottoms_up_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/2013_minneapolis_park_bottoms_up/2013_minneapolis_park_bottoms_up_expected_summary.csv index 1e80c15..fb7389c 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/2013_minneapolis_park_bottoms_up/2013_minneapolis_park_bottoms_up_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/2013_minneapolis_park_bottoms_up/2013_minneapolis_park_bottoms_up_expected_summary.csv @@ -31,8 +31,8 @@ CASPER HILL,1280,2.15%,4,1284,2.16%,-1284,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0, Undeclared Write-ins,342,0.57%,-342,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 Active Ballots,59463,,,59174,,,58876,,,57926,,,56924,,,55274,,,52027,,,49968,,,47268,, Current Round Threshold,14866,,,14866,,,14866,,,14866,,,14866,,,14866,,,14866,,,14866,,,14866,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,67,289,,356,298,,654,950,,1604,1002,,2606,1650,,4256,3247,,7503,2059,,9562,2700,,12262,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,67,289,,356,298,,654,950,,1604,1002,,2606,1650,,4256,3247,,7503,2059,,9562,2700,,12262,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,67,,289,356,,298,654,,950,1604,,1002,2606,,1650,4256,,3247,7503,,2059,9562,,2700,12262,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,67,,289,356,,298,654,,950,1604,,1002,2606,,1650,4256,,3247,7503,,2059,9562,,2700,12262,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/2013_minneapolis_park_hare/2013_minneapolis_park_hare_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/2013_minneapolis_park_hare/2013_minneapolis_park_hare_expected_summary.csv index 9ff5bb1..5f64d3c 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/2013_minneapolis_park_hare/2013_minneapolis_park_hare_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/2013_minneapolis_park_hare/2013_minneapolis_park_hare_expected_summary.csv @@ -31,9 +31,9 @@ CASPER HILL,1280,2.15%,4,1284,2.16%,-1284,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0, Undeclared Write-ins,342,0.57%,-342,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,,0 Active Ballots,59463,,,59174,,,58876,,,57926,,,56924,,,55274,,,52027,,,49968,,,47268,,,0,, Current Round Threshold,19821,,,19821,,,19821,,,19821,,,19821,,,19821,,,19821,,,19821,,,19821,,,19821,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,67,289,,356,298,,654,950,,1604,1002,,2606,1650,,4256,3247,,7503,2059,,9562,2700,,12262,1827.2600,,14089.2600,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,67,289,,356,298,,654,950,,1604,1002,,2606,1650,,4256,3247,,7503,2059,,9562,2700,,12262,1827.2600,,14089.2600,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,67,,289,356,,298,654,,950,1604,,1002,2606,,1650,4256,,3247,7503,,2059,9562,,2700,12262,,1827.2600,14089.2600,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,67,,289,356,,298,654,,950,1604,,1002,2606,,1650,4256,,3247,7503,,2059,9562,,2700,12262,,1827.2600,14089.2600,,0 Residual surplus,0,,,0,,,0,,,0,,,0,,,0,,,0,,,0,,,0,,,1.7400,, diff --git a/src/test/resources/network/brightspots/rcv/test_data/2013_minneapolis_park_sequential/2013_minneapolis_park_sequential_1_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/2013_minneapolis_park_sequential/2013_minneapolis_park_sequential_1_expected_summary.csv index d838abe..54d4748 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/2013_minneapolis_park_sequential/2013_minneapolis_park_sequential_1_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/2013_minneapolis_park_sequential/2013_minneapolis_park_sequential_1_expected_summary.csv @@ -31,8 +31,8 @@ CASPER HILL,1280,2.15%,4,1284,2.16%,-1284,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0, Undeclared Write-ins,342,0.57%,-342,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 Active Ballots,59463,,,59174,,,58876,,,57926,,,56924,,,55274,,,52027,,,49968,,,47268,,,40324,, Current Round Threshold,29732,,,29588,,,29439,,,28964,,,28463,,,27638,,,26014,,,24985,,,23635,,,20163,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,67,289,,356,298,,654,950,,1604,1002,,2606,1650,,4256,3247,,7503,2059,,9562,2700,,12262,6944,,19206,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,67,289,,356,298,,654,950,,1604,1002,,2606,1650,,4256,3247,,7503,2059,,9562,2700,,12262,6944,,19206,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,67,,289,356,,298,654,,950,1604,,1002,2606,,1650,4256,,3247,7503,,2059,9562,,2700,12262,,6944,19206,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,67,,289,356,,298,654,,950,1604,,1002,2606,,1650,4256,,3247,7503,,2059,9562,,2700,12262,,6944,19206,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/2013_minneapolis_park_sequential/2013_minneapolis_park_sequential_2_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/2013_minneapolis_park_sequential/2013_minneapolis_park_sequential_2_expected_summary.csv index cef639d..5c91b61 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/2013_minneapolis_park_sequential/2013_minneapolis_park_sequential_2_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/2013_minneapolis_park_sequential/2013_minneapolis_park_sequential_2_expected_summary.csv @@ -30,8 +30,8 @@ CASPER HILL,1586,2.76%,4,1590,2.78%,-1590,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0, Undeclared Write-ins,356,0.62%,-356,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 Active Ballots,57401,,,57101,,,56735,,,55688,,,54392,,,52274,,,48689,,,44478,,,36914,, Current Round Threshold,28701,,,28551,,,28368,,,27845,,,27197,,,26138,,,24345,,,22240,,,18458,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,2129,300,,2429,366,,2795,1047,,3842,1296,,5138,2118,,7256,3585,,10841,4211,,15052,7564,,22616,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,2129,300,,2429,366,,2795,1047,,3842,1296,,5138,2118,,7256,3585,,10841,4211,,15052,7564,,22616,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,2129,,300,2429,,366,2795,,1047,3842,,1296,5138,,2118,7256,,3585,10841,,4211,15052,,7564,22616,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,2129,,300,2429,,366,2795,,1047,3842,,1296,5138,,2118,7256,,3585,10841,,4211,15052,,7564,22616,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/2013_minneapolis_park_sequential/2013_minneapolis_park_sequential_3_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/2013_minneapolis_park_sequential/2013_minneapolis_park_sequential_3_expected_summary.csv index b4e6948..d7d09aa 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/2013_minneapolis_park_sequential/2013_minneapolis_park_sequential_3_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/2013_minneapolis_park_sequential/2013_minneapolis_park_sequential_3_expected_summary.csv @@ -29,8 +29,8 @@ CASPER HILL,1903,3.48%,5,1908,3.51%,-1908,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0, Undeclared Write-ins,381,0.69%,-381,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 Active Ballots,54598,,,54272,,,53599,,,50679,,,48433,,,46013,,,41986,,,31348,, Current Round Threshold,27300,,,27137,,,26800,,,25340,,,24217,,,23007,,,20994,,,15675,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,4932,326,,5258,673,,5931,2920,,8851,2246,,11097,2420,,13517,4027,,17544,10638,,28182,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,4932,326,,5258,673,,5931,2920,,8851,2246,,11097,2420,,13517,4027,,17544,10638,,28182,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,4932,,326,5258,,673,5931,,2920,8851,,2246,11097,,2420,13517,,4027,17544,,10638,28182,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,4932,,326,5258,,673,5931,,2920,8851,,2246,11097,,2420,13517,,4027,17544,,10638,28182,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/2015_portland_mayor/2015_portland_mayor_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/2015_portland_mayor/2015_portland_mayor_expected_summary.csv index fc7e3dd..40ca5f3 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/2015_portland_mayor/2015_portland_mayor_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/2015_portland_mayor/2015_portland_mayor_expected_summary.csv @@ -36,8 +36,8 @@ Elected,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"Mavodones, Nicholas M. Jr.",, Undeclared Write-ins,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 Active Ballots,98,,,98,,,98,,,98,,,98,,,98,,,98,,,97,,,97,,,97,,,97,,,97,,,97,,,94,, Current Round Threshold,50,,,50,,,50,,,50,,,50,,,50,,,50,,,49,,,49,,,49,,,49,,,49,,,49,,,48,, -Inactive Ballots by by Overvotes,1,0,,1,0,,1,0,,1,0,,1,0,,1,0,,1,0,,1,0,,1,0,,1,0,,1,0,,1,0,,1,2,,3,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,1,,1,0,,1,0,,1,0,,1,0,,1,0,,1,0,,1,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,1,0,,1,0,,1,0,,1,0,,1,0,,1,0,,1,1,,2,0,,2,0,,2,0,,2,0,,2,0,,2,3,,5,0, +Inactive Ballots by Overvotes,1,,0,1,,0,1,,0,1,,0,1,,0,1,,0,1,,0,1,,0,1,,0,1,,0,1,,0,1,,0,1,,2,3,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,1,1,,0,1,,0,1,,0,1,,0,1,,0,1,,0,1,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,1,,0,1,,0,1,,0,1,,0,1,,0,1,,0,1,,1,2,,0,2,,0,2,,0,2,,0,2,,0,2,,3,5,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/2015_portland_mayor_codes/2015_portland_mayor_codes_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/2015_portland_mayor_codes/2015_portland_mayor_codes_expected_summary.csv index fc7e3dd..40ca5f3 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/2015_portland_mayor_codes/2015_portland_mayor_codes_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/2015_portland_mayor_codes/2015_portland_mayor_codes_expected_summary.csv @@ -36,8 +36,8 @@ Elected,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"Mavodones, Nicholas M. Jr.",, Undeclared Write-ins,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 Active Ballots,98,,,98,,,98,,,98,,,98,,,98,,,98,,,97,,,97,,,97,,,97,,,97,,,97,,,94,, Current Round Threshold,50,,,50,,,50,,,50,,,50,,,50,,,50,,,49,,,49,,,49,,,49,,,49,,,49,,,48,, -Inactive Ballots by by Overvotes,1,0,,1,0,,1,0,,1,0,,1,0,,1,0,,1,0,,1,0,,1,0,,1,0,,1,0,,1,0,,1,2,,3,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,1,,1,0,,1,0,,1,0,,1,0,,1,0,,1,0,,1,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,1,0,,1,0,,1,0,,1,0,,1,0,,1,0,,1,1,,2,0,,2,0,,2,0,,2,0,,2,0,,2,3,,5,0, +Inactive Ballots by Overvotes,1,,0,1,,0,1,,0,1,,0,1,,0,1,,0,1,,0,1,,0,1,,0,1,,0,1,,0,1,,0,1,,2,3,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,1,1,,0,1,,0,1,,0,1,,0,1,,0,1,,0,1,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,1,,0,1,,0,1,,0,1,,0,1,,0,1,,0,1,,1,2,,0,2,,0,2,,0,2,,0,2,,0,2,,3,5,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/2017_minneapolis_mayor/2017_minneapolis_mayor_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/2017_minneapolis_mayor/2017_minneapolis_mayor_expected_summary.csv index b3ab213..7beb403 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/2017_minneapolis_mayor/2017_minneapolis_mayor_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/2017_minneapolis_mayor/2017_minneapolis_mayor_expected_summary.csv @@ -39,8 +39,8 @@ Theron Preston Washington,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 Undeclared Write-ins,137,0.13%,-137,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 Active Ballots,104484,,,104398,,,101865,,,99747,,,93578,,,81674,, Current Round Threshold,52243,,,52200,,,50933,,,49874,,,46790,,,40838,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,38,0,,38,0,,38,0,,38,0,,38,0,,38,0, -Inactive Ballots by by Exhausted Choices,37,37,,74,1534,,1608,1291,,2899,3596,,6495,9273,,15768,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,75,86,,161,2533,,2694,2118,,4812,6169,,10981,11904,,22885,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,38,,0,38,,0,38,,0,38,,0,38,,0,38,,0 +Inactive Ballots by Exhausted Choices,37,,37,74,,1534,1608,,1291,2899,,3596,6495,,9273,15768,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,75,,86,161,,2533,2694,,2118,4812,,6169,10981,,11904,22885,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/2018_maine_governor_primary/2018_maine_governor_primary_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/2018_maine_governor_primary/2018_maine_governor_primary_expected_summary.csv index 1864895..3bee248 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/2018_maine_governor_primary/2018_maine_governor_primary_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/2018_maine_governor_primary/2018_maine_governor_primary_expected_summary.csv @@ -28,8 +28,8 @@ Elected,,,,,,,,,,"Mills, Janet T.",, Write-in,748,0.59%,-748,0,0.0%,0,0,0.0%,0,0,0.0%,0 Active Ballots,126139,,,124093,,,122512,,,117253,, Current Round Threshold,63070,,,62047,,,61257,,,58627,, -Inactive Ballots by by Overvotes,430,42,,472,35,,507,73,,580,0, -Inactive Ballots by by Skipped Rankings,146,45,,191,28,,219,78,,297,0, -Inactive Ballots by by Exhausted Choices,0,119,,119,61,,180,92,,272,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,576,2046,,2622,1581,,4203,5259,,9462,0, +Inactive Ballots by Overvotes,430,,42,472,,35,507,,73,580,,0 +Inactive Ballots by Skipped Rankings,146,,45,191,,28,219,,78,297,,0 +Inactive Ballots by Exhausted Choices,0,,119,119,,61,180,,92,272,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,576,,2046,2622,,1581,4203,,5259,9462,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/aliases_cdf_json/aliases_cdf_json_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/aliases_cdf_json/aliases_cdf_json_expected_summary.csv index 669d2dc..bef1462 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/aliases_cdf_json/aliases_cdf_json_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/aliases_cdf_json/aliases_cdf_json_expected_summary.csv @@ -24,8 +24,8 @@ Candidate C Name File 1,6,20.0%,2,8,26.66%,-8,0,0.0%,0 Candidate D Name File 1,4,13.33%,-4,0,0.0%,0,0,0.0%,0 Active Ballots,30,,,30,,,30,, Current Round Threshold,16,,,16,,,16,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0, -Inactive Ballots Total,0,0,,0,0,,0,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,0,0,,0,0,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/aliases_ess_xlsx/aliases_ess_xlsx_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/aliases_ess_xlsx/aliases_ess_xlsx_expected_summary.csv index 43b2d1c..4401427 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/aliases_ess_xlsx/aliases_ess_xlsx_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/aliases_ess_xlsx/aliases_ess_xlsx_expected_summary.csv @@ -24,8 +24,8 @@ C,2,22.22%,0,2,25.0%,-2,0,0.0%,0 D,1,11.11%,-1,0,0.0%,0,0,0.0%,0 Active Ballots,9,,,8,,,8,, Current Round Threshold,5,,,5,,,5,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0, -Inactive Ballots Total,0,1,,1,0,,1,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,1,1,,0,1,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/clear_ballot_kansas_primary/clear_ballot_kansas_primary_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/clear_ballot_kansas_primary/clear_ballot_kansas_primary_expected_summary.csv index 538919b..a595669 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/clear_ballot_kansas_primary/clear_ballot_kansas_primary_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/clear_ballot_kansas_primary/clear_ballot_kansas_primary_expected_summary.csv @@ -31,8 +31,8 @@ Steven Bullock,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 Undeclared Write-ins,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 Active Ballots,50,,,50,,,50,,,50,, Current Round Threshold,26,,,26,,,26,,,26,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,0,0,,0,0,,0,0,,0,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,0,0,,0,0,,0,0,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/continue_tabulation_test/continue_tabulation_test_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/continue_tabulation_test/continue_tabulation_test_expected_summary.csv index 15f7127..13e0b7b 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/continue_tabulation_test/continue_tabulation_test_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/continue_tabulation_test/continue_tabulation_test_expected_summary.csv @@ -23,8 +23,8 @@ Elected,"Vail, Christopher L.",,,,,,,, "Haadoow, Hamza A.",3,16.66%,0,3,16.66%,-3,0,0.0%,0 Active Ballots,18,,,18,,,18,, Current Round Threshold,10,,,10,,,10,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0, -Inactive Ballots Total,0,0,,0,0,,0,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,0,0,,0,0,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/continue_until_two_with_batch_elimination_test/continue_until_two_with_batch_elimination_test_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/continue_until_two_with_batch_elimination_test/continue_until_two_with_batch_elimination_test_expected_summary.csv index 435d0a1..4ec1b30 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/continue_until_two_with_batch_elimination_test/continue_until_two_with_batch_elimination_test_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/continue_until_two_with_batch_elimination_test/continue_until_two_with_batch_elimination_test_expected_summary.csv @@ -27,8 +27,8 @@ F,1,1.0%,0,1,1.0%,-1,0,0.0%,0,0,0.0%,0 G,1,1.0%,0,1,1.0%,-1,0,0.0%,0,0,0.0%,0 Active Ballots,100,,,100,,,91,,,76,, Current Round Threshold,51,,,51,,,46,,,39,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,0,0,,0,9,,9,15,,24,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,0,0,,9,9,,15,24,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/dominion_alaska/dominion_alaska_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/dominion_alaska/dominion_alaska_expected_summary.csv index 3600416..ea46fae 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/dominion_alaska/dominion_alaska_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/dominion_alaska/dominion_alaska_expected_summary.csv @@ -29,8 +29,8 @@ Elizabeth Warren,96,10.18%,15,111,11.77%,8,119,12.61%,-119,0,0.0%,0,0,0.0%,0,0,0 Undeclared Write-ins,104,11.02%,-104,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 Active Ballots,943,,,943,,,943,,,943,,,942,,,938,,,894,,,793,, Current Round Threshold,472,,,472,,,472,,,472,,,472,,,470,,,448,,,397,, -Inactive Ballots by by Overvotes,2,0,,2,0,,2,0,,2,1,,3,2,,5,1,,6,1,,7,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,2,0,,2,0,,2,0,,2,1,,3,4,,7,44,,51,101,,152,0, +Inactive Ballots by Overvotes,2,,0,2,,0,2,,0,2,,1,3,,2,5,,1,6,,1,7,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,2,,0,2,,0,2,,0,2,,1,3,,4,7,,44,51,,101,152,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/dominion_kansas/dominion_kansas_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/dominion_kansas/dominion_kansas_expected_summary.csv index e40ebf3..12e72a4 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/dominion_kansas/dominion_kansas_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/dominion_kansas/dominion_kansas_expected_summary.csv @@ -29,8 +29,8 @@ Joseph R. Biden,496,10.55%,63,559,11.9%,-559,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 Undeclared Write-ins,513,10.92%,-513,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 Active Ballots,4697,,,4696,,,4695,,,4694,,,4688,,,4648,,,4446,,,3923,, Current Round Threshold,2349,,,2349,,,2348,,,2348,,,2345,,,2325,,,2224,,,1962,, -Inactive Ballots by by Overvotes,13,1,,14,1,,15,1,,16,6,,22,1,,23,5,,28,5,,33,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,13,1,,14,1,,15,1,,16,6,,22,40,,62,202,,264,523,,787,0, +Inactive Ballots by Overvotes,13,,1,14,,1,15,,1,16,,6,22,,1,23,,5,28,,5,33,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,13,,1,14,,1,15,,1,16,,6,22,,40,62,,202,264,,523,787,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/dominion_multi_file/dominion_multi_file_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/dominion_multi_file/dominion_multi_file_expected_summary.csv index 02fa87a..abde13a 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/dominion_multi_file/dominion_multi_file_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/dominion_multi_file/dominion_multi_file_expected_summary.csv @@ -25,8 +25,8 @@ Spencer Simonson,1,5.88%,0 Undeclared Write-ins,0,0.0%,0 Active Ballots,17,, Current Round Threshold,9,, -Inactive Ballots by by Overvotes,0,0, -Inactive Ballots by by Skipped Rankings,0,0, -Inactive Ballots by by Exhausted Choices,0,0, -Inactive Ballots by by Repeated Rankings,0,0, -Inactive Ballots Total,0,0, +Inactive Ballots by Overvotes,0,,0 +Inactive Ballots by Skipped Rankings,0,,0 +Inactive Ballots by Exhausted Choices,0,,0 +Inactive Ballots by Repeated Rankings,0,,0 +Inactive Ballots Total,0,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/dominion_no_precinct_data/dominion_no_precinct_data_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/dominion_no_precinct_data/dominion_no_precinct_data_expected_summary.csv index 0475cd0..d4a37a1 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/dominion_no_precinct_data/dominion_no_precinct_data_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/dominion_no_precinct_data/dominion_no_precinct_data_expected_summary.csv @@ -29,8 +29,8 @@ Tulsi Gabbard,89,9.47%,19,108,11.5%,22,130,13.84%,19,149,15.86%,26,175,18.63%,-1 Undeclared Write-ins,117,12.46%,-117,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 Active Ballots,939,,,939,,,939,,,939,,,939,,,935,,,903,,,795,, Current Round Threshold,470,,,470,,,470,,,470,,,470,,,468,,,452,,,398,, -Inactive Ballots by by Overvotes,4,0,,4,0,,4,0,,4,0,,4,1,,5,1,,6,1,,7,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,4,0,,4,0,,4,0,,4,0,,4,4,,8,32,,40,108,,148,0, +Inactive Ballots by Overvotes,4,,0,4,,0,4,,0,4,,0,4,,1,5,,1,6,,1,7,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,4,,0,4,,0,4,,0,4,,0,4,,4,8,,32,40,,108,148,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/dominion_wyoming/dominion_wyoming_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/dominion_wyoming/dominion_wyoming_expected_summary.csv index 0475cd0..d4a37a1 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/dominion_wyoming/dominion_wyoming_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/dominion_wyoming/dominion_wyoming_expected_summary.csv @@ -29,8 +29,8 @@ Tulsi Gabbard,89,9.47%,19,108,11.5%,22,130,13.84%,19,149,15.86%,26,175,18.63%,-1 Undeclared Write-ins,117,12.46%,-117,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 Active Ballots,939,,,939,,,939,,,939,,,939,,,935,,,903,,,795,, Current Round Threshold,470,,,470,,,470,,,470,,,470,,,468,,,452,,,398,, -Inactive Ballots by by Overvotes,4,0,,4,0,,4,0,,4,0,,4,1,,5,1,,6,1,,7,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,4,0,,4,0,,4,0,,4,0,,4,4,,8,32,,40,108,,148,0, +Inactive Ballots by Overvotes,4,,0,4,,0,4,,0,4,,0,4,,1,5,,1,6,,1,7,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,4,,0,4,,0,4,,0,4,,0,4,,4,8,,32,40,,108,148,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/duplicate_test/duplicate_test_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/duplicate_test/duplicate_test_expected_summary.csv index 6c302e7..18ea81d 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/duplicate_test/duplicate_test_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/duplicate_test/duplicate_test_expected_summary.csv @@ -23,8 +23,8 @@ Banana,4,36.36%,0,4,44.44%,0 Durian,3,27.27%,-3,0,0.0%,0 Active Ballots,11,,,9,, Current Round Threshold,6,,,5,, -Inactive Ballots by by Overvotes,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0, -Inactive Ballots by by Repeated Rankings,0,2,,2,0, -Inactive Ballots Total,0,2,,2,0, +Inactive Ballots by Overvotes,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,2,2,,0 +Inactive Ballots Total,0,,2,2,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/excluded_test/excluded_test_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/excluded_test/excluded_test_expected_summary.csv index c2fd679..dc8a0b2 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/excluded_test/excluded_test_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/excluded_test/excluded_test_expected_summary.csv @@ -21,8 +21,8 @@ Elected,George Gervin,, George Gervin,3,100.0%,0 Active Ballots,3,, Current Round Threshold,2,, -Inactive Ballots by by Overvotes,0,0, -Inactive Ballots by by Skipped Rankings,0,0, -Inactive Ballots by by Exhausted Choices,0,0, -Inactive Ballots by by Repeated Rankings,0,0, -Inactive Ballots Total,0,0, +Inactive Ballots by Overvotes,0,,0 +Inactive Ballots by Skipped Rankings,0,,0 +Inactive Ballots by Exhausted Choices,0,,0 +Inactive Ballots by Repeated Rankings,0,,0 +Inactive Ballots Total,0,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/exhaust_if_multiple_continuing/exhaust_if_multiple_continuing_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/exhaust_if_multiple_continuing/exhaust_if_multiple_continuing_expected_summary.csv index 6bc431b..412f814 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/exhaust_if_multiple_continuing/exhaust_if_multiple_continuing_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/exhaust_if_multiple_continuing/exhaust_if_multiple_continuing_expected_summary.csv @@ -24,8 +24,8 @@ D,1,16.66%,0,1,16.66%,-1,0,0.0%,0 A,0,0.0%,0,0,0.0%,0,0,0.0%,0 Active Ballots,6,,,6,,,5,, Current Round Threshold,4,,,4,,,3,, -Inactive Ballots by by Overvotes,3,0,,3,0,,3,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0, -Inactive Ballots Total,3,0,,3,1,,4,0, +Inactive Ballots by Overvotes,3,,0,3,,0,3,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0 +Inactive Ballots Total,3,,0,3,,1,4,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/first_round_determines_threshold_test/first_round_determines_threshold_test_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/first_round_determines_threshold_test/first_round_determines_threshold_test_expected_summary.csv index 4aab123..e656961 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/first_round_determines_threshold_test/first_round_determines_threshold_test_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/first_round_determines_threshold_test/first_round_determines_threshold_test_expected_summary.csv @@ -23,8 +23,8 @@ Elected,,,,"Vail, Christopher L.",, "Carmona, Ralph C.",5,31.25%,0,5,45.45%,0 Active Ballots,16,,,11,, Current Round Threshold,9,,,9,, -Inactive Ballots by by Overvotes,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0, -Inactive Ballots Total,0,5,,5,0, +Inactive Ballots by Overvotes,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0 +Inactive Ballots Total,0,,5,5,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/first_round_determines_threshold_tiebreaker_test/first_round_determines_threshold_tiebreaker_test_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/first_round_determines_threshold_tiebreaker_test/first_round_determines_threshold_tiebreaker_test_expected_summary.csv index a7eaec3..48b1745 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/first_round_determines_threshold_tiebreaker_test/first_round_determines_threshold_tiebreaker_test_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/first_round_determines_threshold_tiebreaker_test/first_round_determines_threshold_tiebreaker_test_expected_summary.csv @@ -23,8 +23,8 @@ Elected,,,,"Vail, Christopher L.",, "Haadoow, Hamza A.",5,29.41%,-5,0,0.0%,0 Active Ballots,17,,,12,, Current Round Threshold,9,,,9,, -Inactive Ballots by by Overvotes,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0, -Inactive Ballots Total,0,5,,5,0, +Inactive Ballots by Overvotes,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0 +Inactive Ballots Total,0,,5,5,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/generic_csv_test/generic_csv_test_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/generic_csv_test/generic_csv_test_expected_summary.csv index a3599f2..924d258 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/generic_csv_test/generic_csv_test_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/generic_csv_test/generic_csv_test_expected_summary.csv @@ -25,8 +25,8 @@ Broccoli,3,11.53%,1,4,15.38%,-4,0,0.0%,0,0,0.0%,0 Undeclared Write-ins,6,23.07%,-6,0,0.0%,0,0,0.0%,0,0,0.0%,0 Active Ballots,26,,,26,,,26,,,26,, Current Round Threshold,14,,,14,,,14,,,14,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,0,0,,0,0,,0,0,,0,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,0,0,,0,0,,0,0,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/hart_cedar_park_school_board/hart_cedar_park_school_board_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/hart_cedar_park_school_board/hart_cedar_park_school_board_expected_summary.csv index ffdd0ce..54c3749 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/hart_cedar_park_school_board/hart_cedar_park_school_board_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/hart_cedar_park_school_board/hart_cedar_park_school_board_expected_summary.csv @@ -28,8 +28,8 @@ Betty McCollum,0,0.0%,0 Undeclared Write-ins,0,0.0%,0 Active Ballots,7,, Current Round Threshold,4,, -Inactive Ballots by by Overvotes,0,0, -Inactive Ballots by by Skipped Rankings,0,0, -Inactive Ballots by by Exhausted Choices,0,0, -Inactive Ballots by by Repeated Rankings,0,0, -Inactive Ballots Total,0,0, +Inactive Ballots by Overvotes,0,,0 +Inactive Ballots by Skipped Rankings,0,,0 +Inactive Ballots by Exhausted Choices,0,,0 +Inactive Ballots by Repeated Rankings,0,,0 +Inactive Ballots Total,0,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/hart_travis_county_officers/hart_travis_county_officers_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/hart_travis_county_officers/hart_travis_county_officers_expected_summary.csv index 19f3b4b..71e35c7 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/hart_travis_county_officers/hart_travis_county_officers_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/hart_travis_county_officers/hart_travis_county_officers_expected_summary.csv @@ -25,8 +25,8 @@ Jim Sylvester,0,0.0%,0 Bruce Elfant,0,0.0%,0 Active Ballots,1,, Current Round Threshold,1,, -Inactive Ballots by by Overvotes,6,0, -Inactive Ballots by by Skipped Rankings,0,0, -Inactive Ballots by by Exhausted Choices,0,0, -Inactive Ballots by by Repeated Rankings,0,0, -Inactive Ballots Total,6,0, +Inactive Ballots by Overvotes,6,,0 +Inactive Ballots by Skipped Rankings,0,,0 +Inactive Ballots by Exhausted Choices,0,,0 +Inactive Ballots by Repeated Rankings,0,,0 +Inactive Ballots Total,6,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/minimum_threshold_test/minimum_threshold_test_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/minimum_threshold_test/minimum_threshold_test_expected_summary.csv index ef1ca4c..59df4c1 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/minimum_threshold_test/minimum_threshold_test_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/minimum_threshold_test/minimum_threshold_test_expected_summary.csv @@ -25,8 +25,8 @@ Garfield,1,10.0%,-1,0,0.0%,0 Odie,0,0.0%,0,0,0.0%,0 Active Ballots,10,,,10,, Current Round Threshold,6,,,6,, -Inactive Ballots by by Overvotes,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0, -Inactive Ballots Total,0,0,,0,0, +Inactive Ballots by Overvotes,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0 +Inactive Ballots Total,0,,0,0,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/minneapolis_multi_seat_threshold/minneapolis_multi_seat_threshold_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/minneapolis_multi_seat_threshold/minneapolis_multi_seat_threshold_expected_summary.csv index f090c25..7badfe8 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/minneapolis_multi_seat_threshold/minneapolis_multi_seat_threshold_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/minneapolis_multi_seat_threshold/minneapolis_multi_seat_threshold_expected_summary.csv @@ -26,8 +26,8 @@ F,3,10.34%,0,3,10.71%,0.0000,3.0000,15.0%,-3.0000,0,0.0%,0,0,0.0%,0,0,,0 D,2,6.89%,-2,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,,0 Active Ballots,29,,,28,,,20.0000,,,20.0000,,,20.0000,,,0,, Current Round Threshold,8,,,8,,,8,,,8,,,8,,,8,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,1,1,,2,0,,2,0,,2,0.0000,,2.0000,0.6000,,2.6000,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0,,0,0,,0,2.6000,,2.6000,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,1,1,,2,0,,2,0,,2,0.0000,,2.0000,4.0000,,6.0000,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,1,,1,2,,0,2,,0,2,,0.0000,2.0000,,0.6000,2.6000,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,0,0,,2.6000,2.6000,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,1,,1,2,,0,2,,0,2,,0.0000,2.0000,,4.0000,6.0000,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/missing_precinct_example/missing_precinct_example_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/missing_precinct_example/missing_precinct_example_expected_summary.csv index fbcd3e0..2bc4497 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/missing_precinct_example/missing_precinct_example_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/missing_precinct_example/missing_precinct_example_expected_summary.csv @@ -39,8 +39,8 @@ Al Flowers,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 Undeclared Write-ins,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 Active Ballots,4,,,4,,,4,,,4,,,2,, Current Round Threshold,3,,,3,,,3,,,3,,,2,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0,,0,2,,2,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,0,0,,0,0,,0,0,,0,2,,2,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,2,2,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,0,0,,0,0,,0,0,,2,2,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/multi_seat_bottoms_up_with_threshold/multi_seat_bottoms_up_with_threshold_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/multi_seat_bottoms_up_with_threshold/multi_seat_bottoms_up_with_threshold_expected_summary.csv index 4cc0a7b..d0e9835 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/multi_seat_bottoms_up_with_threshold/multi_seat_bottoms_up_with_threshold_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/multi_seat_bottoms_up_with_threshold/multi_seat_bottoms_up_with_threshold_expected_summary.csv @@ -28,8 +28,8 @@ E,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 F,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 Active Ballots,21,,,21,,,21,,,21,,,21,, Current Round Threshold,3.1500,,,3.1500,,,3.1500,,,3.1500,,,3.1500,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,0,0,,0,0,,0,0,,0,0,,0,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,0,0,,0,0,,0,0,,0,0,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/multi_seat_uwi_test/multi_seat_uwi_test_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/multi_seat_uwi_test/multi_seat_uwi_test_expected_summary.csv index d996084..eb2a4ba 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/multi_seat_uwi_test/multi_seat_uwi_test_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/multi_seat_uwi_test/multi_seat_uwi_test_expected_summary.csv @@ -24,8 +24,8 @@ C,2,13.33%,0,2,22.22%,0,2,40.0%,-2,0,0.0%,0,0,,0 Undeclared Write-ins,4,26.66%,0,4,44.44%,-4,0,0.0%,0,0,0.0%,0,0,,0 Active Ballots,15,,,9,,,5,,,3,,,0,, Current Round Threshold,6,,,6,,,6,,,6,,,6,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,0,0.0000,,0.0000,4.0000,,4.0000,2.0000,,6.0000,0.0000,,6.0000,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,0.0000,0.0000,,4.0000,4.0000,,2.0000,6.0000,,0.0000,6.0000,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/nist_xml_cdf_2/nist_xml_cdf_2_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/nist_xml_cdf_2/nist_xml_cdf_2_expected_summary.csv index e07d1e9..d93f9ce 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/nist_xml_cdf_2/nist_xml_cdf_2_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/nist_xml_cdf_2/nist_xml_cdf_2_expected_summary.csv @@ -23,8 +23,8 @@ John Kasich and Mary Taylor,0,,0,0,,0,0,,0 Anita Rios and Bob Fitrakis,0,,0,0,,0,0,,0 Active Ballots,0,,,0,,,0,, Current Round Threshold,1,,,1,,,1,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0, -Inactive Ballots Total,0,0,,0,0,,0,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,0,0,,0,0,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/precinct_example/precinct_example_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/precinct_example/precinct_example_expected_summary.csv index ebe4a07..a9a2d89 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/precinct_example/precinct_example_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/precinct_example/precinct_example_expected_summary.csv @@ -39,8 +39,8 @@ Troy Benjegerdes,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 Undeclared Write-ins,1,1.01%,-1,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 Active Ballots,99,,,98,,,96,,,90,,,83,, Current Round Threshold,50,,,50,,,49,,,46,,,42,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,1,,1,2,,3,7,,10,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,0,1,,1,2,,3,6,,9,7,,16,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,1,1,,2,3,,7,10,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,1,1,,2,3,,6,9,,7,16,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/sequential_with_batch/sequential_with_batch_1_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/sequential_with_batch/sequential_with_batch_1_expected_summary.csv index b5a47d7..8ff734e 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/sequential_with_batch/sequential_with_batch_1_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/sequential_with_batch/sequential_with_batch_1_expected_summary.csv @@ -26,8 +26,8 @@ E,0,0.0%,0 F,0,0.0%,0 Active Ballots,9,, Current Round Threshold,5,, -Inactive Ballots by by Overvotes,0,0, -Inactive Ballots by by Skipped Rankings,0,0, -Inactive Ballots by by Exhausted Choices,0,0, -Inactive Ballots by by Repeated Rankings,0,0, -Inactive Ballots Total,0,0, +Inactive Ballots by Overvotes,0,,0 +Inactive Ballots by Skipped Rankings,0,,0 +Inactive Ballots by Exhausted Choices,0,,0 +Inactive Ballots by Repeated Rankings,0,,0 +Inactive Ballots Total,0,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/sequential_with_batch/sequential_with_batch_2_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/sequential_with_batch/sequential_with_batch_2_expected_summary.csv index 973fe4c..1bc914c 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/sequential_with_batch/sequential_with_batch_2_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/sequential_with_batch/sequential_with_batch_2_expected_summary.csv @@ -25,8 +25,8 @@ E,0,0.0%,0,0,0.0%,0,0,0.0%,0 F,0,0.0%,0,0,0.0%,0,0,0.0%,0 Active Ballots,5,,,4,,,2,, Current Round Threshold,3,,,3,,,2,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,4,1,,5,2,,7,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0, -Inactive Ballots Total,4,1,,5,2,,7,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,4,,1,5,,2,7,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0 +Inactive Ballots Total,4,,1,5,,2,7,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/sequential_with_batch/sequential_with_batch_3_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/sequential_with_batch/sequential_with_batch_3_expected_summary.csv index 64f0d90..3496873 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/sequential_with_batch/sequential_with_batch_3_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/sequential_with_batch/sequential_with_batch_3_expected_summary.csv @@ -24,8 +24,8 @@ E,0,0.0%,0 F,0,0.0%,0 Active Ballots,3,, Current Round Threshold,2,, -Inactive Ballots by by Overvotes,0,0, -Inactive Ballots by by Skipped Rankings,0,0, -Inactive Ballots by by Exhausted Choices,6,0, -Inactive Ballots by by Repeated Rankings,0,0, -Inactive Ballots Total,6,0, +Inactive Ballots by Overvotes,0,,0 +Inactive Ballots by Skipped Rankings,0,,0 +Inactive Ballots by Exhausted Choices,6,,0 +Inactive Ballots by Repeated Rankings,0,,0 +Inactive Ballots Total,6,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/sequential_with_continue_until_two/sequential_with_continue_until_two_1_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/sequential_with_continue_until_two/sequential_with_continue_until_two_1_expected_summary.csv index b78732f..22ce501 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/sequential_with_continue_until_two/sequential_with_continue_until_two_1_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/sequential_with_continue_until_two/sequential_with_continue_until_two_1_expected_summary.csv @@ -26,8 +26,8 @@ E,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 F,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 Active Ballots,9,,,9,,,9,,,9,,,8,,,7,, Current Round Threshold,5,,,5,,,5,,,5,,,5,,,4,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0,,0,1,,1,1,,2,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,0,0,,0,0,,0,0,,0,1,,1,1,,2,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,1,1,,1,2,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,0,0,,0,0,,0,0,,1,1,,1,2,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/sequential_with_continue_until_two/sequential_with_continue_until_two_2_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/sequential_with_continue_until_two/sequential_with_continue_until_two_2_expected_summary.csv index 2d04fd0..205bd26 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/sequential_with_continue_until_two/sequential_with_continue_until_two_2_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/sequential_with_continue_until_two/sequential_with_continue_until_two_2_expected_summary.csv @@ -25,8 +25,8 @@ E,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 F,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 Active Ballots,5,,,5,,,5,,,4,,,2,, Current Round Threshold,3,,,3,,,3,,,3,,,2,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,4,0,,4,0,,4,1,,5,2,,7,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,4,0,,4,0,,4,1,,5,2,,7,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,4,,0,4,,0,4,,1,5,,2,7,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,4,,0,4,,0,4,,1,5,,2,7,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/sequential_with_continue_until_two/sequential_with_continue_until_two_3_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/sequential_with_continue_until_two/sequential_with_continue_until_two_3_expected_summary.csv index 072549c..36ada71 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/sequential_with_continue_until_two/sequential_with_continue_until_two_3_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/sequential_with_continue_until_two/sequential_with_continue_until_two_3_expected_summary.csv @@ -24,8 +24,8 @@ E,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 F,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 Active Ballots,3,,,3,,,3,,,3,, Current Round Threshold,2,,,2,,,2,,,2,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,6,0,,6,0,,6,0,,6,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,6,0,,6,0,,6,0,,6,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,6,,0,6,,0,6,,0,6,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,6,,0,6,,0,6,,0,6,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/skip_to_next_test/skip_to_next_test_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/skip_to_next_test/skip_to_next_test_expected_summary.csv index a8eace8..51e012c 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/skip_to_next_test/skip_to_next_test_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/skip_to_next_test/skip_to_next_test_expected_summary.csv @@ -24,8 +24,8 @@ C,3,20.0%,1,4,26.66%,-4,0,0.0%,0 D,1,6.66%,-1,0,0.0%,0,0,0.0%,0 Active Ballots,15,,,15,,,14,, Current Round Threshold,8,,,8,,,8,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,1,,1,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0, -Inactive Ballots Total,0,0,,0,1,,1,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,1,1,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,0,0,,1,1,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/stop_tabulation_early_test/stop_tabulation_early_test_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/stop_tabulation_early_test/stop_tabulation_early_test_expected_summary.csv index 6ee06c8..f1e7343 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/stop_tabulation_early_test/stop_tabulation_early_test_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/stop_tabulation_early_test/stop_tabulation_early_test_expected_summary.csv @@ -23,8 +23,8 @@ George Gervin,3,33.33%,0,3,50.0%,0 Mookie Blaylock,3,33.33%,0,3,50.0%,0 Active Ballots,9,,,6,, Current Round Threshold,5,,,4,, -Inactive Ballots by by Overvotes,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0, -Inactive Ballots Total,0,3,,3,0, +Inactive Ballots by Overvotes,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0 +Inactive Ballots Total,0,,3,3,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/test_set_0_skipped_first_choice/test_set_0_skipped_first_choice_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/test_set_0_skipped_first_choice/test_set_0_skipped_first_choice_expected_summary.csv index e71f364..990b989 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/test_set_0_skipped_first_choice/test_set_0_skipped_first_choice_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/test_set_0_skipped_first_choice/test_set_0_skipped_first_choice_expected_summary.csv @@ -24,8 +24,8 @@ Candidate C Name,3,25.0%,0,3,25.0%,-3,0,0.0%,0 Candidate D Name,1,8.33%,-1,0,0.0%,0,0,0.0%,0 Active Ballots,12,,,12,,,11,, Current Round Threshold,7,,,7,,,6,, -Inactive Ballots by by Overvotes,0,0,,0,1,,1,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0, -Inactive Ballots Total,0,0,,0,1,,1,0, +Inactive Ballots by Overvotes,0,,0,0,,1,1,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,0,0,,1,1,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/test_set_1_exhaust_at_overvote/test_set_1_exhaust_at_overvote_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/test_set_1_exhaust_at_overvote/test_set_1_exhaust_at_overvote_expected_summary.csv index 68a8659..cae33a8 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/test_set_1_exhaust_at_overvote/test_set_1_exhaust_at_overvote_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/test_set_1_exhaust_at_overvote/test_set_1_exhaust_at_overvote_expected_summary.csv @@ -24,8 +24,8 @@ Candidate C Name,2,14.28%,1,3,21.42%,-3,0,0.0%,0 Candidate D Name,1,7.14%,-1,0,0.0%,0,0,0.0%,0 Active Ballots,14,,,14,,,13,, Current Round Threshold,8,,,8,,,7,, -Inactive Ballots by by Overvotes,1,0,,1,1,,2,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0, -Inactive Ballots Total,1,0,,1,1,,2,0, +Inactive Ballots by Overvotes,1,,0,1,,1,2,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0 +Inactive Ballots Total,1,,0,1,,1,2,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/test_set_2_overvote_skip_to_next/test_set_2_overvote_skip_to_next_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/test_set_2_overvote_skip_to_next/test_set_2_overvote_skip_to_next_expected_summary.csv index 12a118d..d1d494c 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/test_set_2_overvote_skip_to_next/test_set_2_overvote_skip_to_next_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/test_set_2_overvote_skip_to_next/test_set_2_overvote_skip_to_next_expected_summary.csv @@ -24,8 +24,8 @@ Candidate C Name,2,14.28%,1,3,21.42%,-3,0,0.0%,0 Candidate D Name,1,7.14%,-1,0,0.0%,0,0,0.0%,0 Active Ballots,14,,,14,,,13,, Current Round Threshold,8,,,8,,,7,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,1,0,,1,1,,2,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0, -Inactive Ballots Total,1,0,,1,1,,2,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,1,,0,1,,1,2,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0 +Inactive Ballots Total,1,,0,1,,1,2,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/test_set_3_skipped_choice_exhaust/test_set_3_skipped_choice_exhaust_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/test_set_3_skipped_choice_exhaust/test_set_3_skipped_choice_exhaust_expected_summary.csv index b89e8d8..18e03f8 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/test_set_3_skipped_choice_exhaust/test_set_3_skipped_choice_exhaust_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/test_set_3_skipped_choice_exhaust/test_set_3_skipped_choice_exhaust_expected_summary.csv @@ -24,8 +24,8 @@ Candidate C Name,2,14.28%,1,3,21.42%,-3,0,0.0%,0 Candidate D Name,1,7.14%,-1,0,0.0%,0,0,0.0%,0 Active Ballots,14,,,14,,,12,, Current Round Threshold,8,,,8,,,7,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,1,0,,1,2,,3,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0, -Inactive Ballots Total,1,0,,1,2,,3,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,1,,0,1,,2,3,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0 +Inactive Ballots Total,1,,0,1,,2,3,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/test_set_4_skipped_choice_next/test_set_4_skipped_choice_next_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/test_set_4_skipped_choice_next/test_set_4_skipped_choice_next_expected_summary.csv index 6909da9..3c64158 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/test_set_4_skipped_choice_next/test_set_4_skipped_choice_next_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/test_set_4_skipped_choice_next/test_set_4_skipped_choice_next_expected_summary.csv @@ -24,8 +24,8 @@ Candidate C Name,2,13.33%,1,3,20.0%,-3,0,0.0%,0 Candidate D Name,1,6.66%,-1,0,0.0%,0,0,0.0%,0 Active Ballots,15,,,15,,,15,, Current Round Threshold,8,,,8,,,8,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0, -Inactive Ballots Total,0,0,,0,0,,0,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,0,0,,0,0,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/test_set_5_two_skipped_choice_exhaust/test_set_5_two_skipped_choice_exhaust_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/test_set_5_two_skipped_choice_exhaust/test_set_5_two_skipped_choice_exhaust_expected_summary.csv index e31f7e4..a3e65b5 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/test_set_5_two_skipped_choice_exhaust/test_set_5_two_skipped_choice_exhaust_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/test_set_5_two_skipped_choice_exhaust/test_set_5_two_skipped_choice_exhaust_expected_summary.csv @@ -24,8 +24,8 @@ Candidate C Name,2,13.33%,1,3,20.0%,-3,0,0.0%,0 Candidate D Name,1,6.66%,-1,0,0.0%,0,0,0.0%,0 Active Ballots,15,,,15,,,14,, Current Round Threshold,8,,,8,,,8,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,1,,1,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0, -Inactive Ballots Total,0,0,,0,1,,1,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,1,1,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,0,0,,1,1,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/test_set_6_duplicate_exhaust/test_set_6_duplicate_exhaust_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/test_set_6_duplicate_exhaust/test_set_6_duplicate_exhaust_expected_summary.csv index 7055664..a5bd13a 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/test_set_6_duplicate_exhaust/test_set_6_duplicate_exhaust_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/test_set_6_duplicate_exhaust/test_set_6_duplicate_exhaust_expected_summary.csv @@ -24,8 +24,8 @@ Candidate B Name,4,26.66%,1,5,35.71%,2,7,58.33%,0 Candidate D Name,2,13.33%,-2,0,0.0%,0,0,0.0%,0 Active Ballots,15,,,14,,,12,, Current Round Threshold,8,,,8,,,7,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0, -Inactive Ballots by by Repeated Rankings,0,1,,1,2,,3,0, -Inactive Ballots Total,0,1,,1,2,,3,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,1,1,,2,3,,0 +Inactive Ballots Total,0,,1,1,,2,3,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/test_set_7_duplicate_skip_to_next/test_set_7_duplicate_skip_to_next_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/test_set_7_duplicate_skip_to_next/test_set_7_duplicate_skip_to_next_expected_summary.csv index 51367f3..4beaf90 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/test_set_7_duplicate_skip_to_next/test_set_7_duplicate_skip_to_next_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/test_set_7_duplicate_skip_to_next/test_set_7_duplicate_skip_to_next_expected_summary.csv @@ -24,8 +24,8 @@ Candidate C Name,3,20.0%,1,4,26.66%,-4,0,0.0%,0 Candidate D Name,2,13.33%,-2,0,0.0%,0,0,0.0%,0 Active Ballots,15,,,15,,,15,, Current Round Threshold,8,,,8,,,8,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0, -Inactive Ballots Total,0,0,,0,0,,0,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,0,0,,0,0,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/test_set_8_multi_cdf/test_set_8_multi_cdf_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/test_set_8_multi_cdf/test_set_8_multi_cdf_expected_summary.csv index ed0dcb8..c94a2e8 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/test_set_8_multi_cdf/test_set_8_multi_cdf_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/test_set_8_multi_cdf/test_set_8_multi_cdf_expected_summary.csv @@ -24,8 +24,8 @@ Candidate C Name,6,25.0%,0,6,25.0%,-6,0,0.0%,0 Candidate D Name,2,8.33%,-2,0,0.0%,0,0,0.0%,0 Active Ballots,24,,,24,,,22,, Current Round Threshold,13,,,13,,,12,, -Inactive Ballots by by Overvotes,0,0,,0,2,,2,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0, -Inactive Ballots Total,0,0,,0,2,,2,0, +Inactive Ballots by Overvotes,0,,0,0,,2,2,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,0,0,,2,2,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/test_set_allow_only_one_winner_per_round/test_set_allow_only_one_winner_per_round_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/test_set_allow_only_one_winner_per_round/test_set_allow_only_one_winner_per_round_expected_summary.csv index f3c383a..f977f04 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/test_set_allow_only_one_winner_per_round/test_set_allow_only_one_winner_per_round_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/test_set_allow_only_one_winner_per_round/test_set_allow_only_one_winner_per_round_expected_summary.csv @@ -24,9 +24,9 @@ C,3,33.33%,0,3,44.44%,1.4994,4.4994,100.0%,-2.2493,2.2501,107.17%,0 D,0,0.0%,0,0,0.0%,0,0,0.0%,2.0994,2.0994,100.0%,0 Active Ballots,9,,,6.7497,,,4.4994,,,2.0994,, Current Round Threshold,2.2501,,,2.2501,,,2.2501,,,2.2501,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0.1497,,0.1497,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,0,0,,0,0,,0,0.1497,,0.1497,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0.1497,0.1497,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,0,0,,0,0,,0.1497,0.1497,,0 Residual surplus,0,,,0.0002,,,0.0004,,,0.0006,, diff --git a/src/test/resources/network/brightspots/rcv/test_data/test_set_multi_winner_fractional_threshold/test_set_multi_winner_fractional_threshold_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/test_set_multi_winner_fractional_threshold/test_set_multi_winner_fractional_threshold_expected_summary.csv index f5f717b..f023e28 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/test_set_multi_winner_fractional_threshold/test_set_multi_winner_fractional_threshold_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/test_set_multi_winner_fractional_threshold/test_set_multi_winner_fractional_threshold_expected_summary.csv @@ -26,9 +26,9 @@ Candidate F Name,3,10.34%,0,3,10.71%,0.0937,3.0937,14.9%,-3.0937,0,0.0%,0,0,0.0% Candidate D Name,2,6.89%,-2,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,,0 Active Ballots,29,,,28,,,20.7496,,,20.7496,,,20.3748,,,0,, Current Round Threshold,7.2501,,,7.2501,,,7.2501,,,7.2501,,,7.2501,,,7.2501,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,1,1,,2,0,,2,0,,2,0.1874,,2.1874,0.8582,,3.0456,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0,,0,0,,0,3.8760,,3.8760,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,1,1,,2,0,,2,0,,2,0.3748,,2.3748,5.8741,,8.2489,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,1,,1,2,,0,2,,0,2,,0.1874,2.1874,,0.8582,3.0456,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,0,0,,3.8760,3.8760,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,1,,1,2,,0,2,,0,2,,0.3748,2.3748,,5.8741,8.2489,,0 Residual surplus,0,,,0,,,0.0003,,,0.0003,,,0.0003,,,0.0008,, diff --git a/src/test/resources/network/brightspots/rcv/test_data/test_set_multi_winner_whole_threshold/test_set_multi_winner_whole_threshold_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/test_set_multi_winner_whole_threshold/test_set_multi_winner_whole_threshold_expected_summary.csv index 1437d4c..1cc6431 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/test_set_multi_winner_whole_threshold/test_set_multi_winner_whole_threshold_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/test_set_multi_winner_whole_threshold/test_set_multi_winner_whole_threshold_expected_summary.csv @@ -26,9 +26,9 @@ Candidate F Name,3,10.34%,0.1111,3.1111,14.81%,0.1111,3.2222,16.11%,-3.2222,0,0. Candidate D Name,2,6.89%,0.1111,2.1111,10.05%,-2.1111,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,,0 Active Ballots,29,,,20.9999,,,19.9999,,,19.9999,,,19.5555,,,0,, Current Round Threshold,8,,,8,,,8,,,8,,,8,,,8,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,1,0,,1,1,,2,0,,2,0.2222,,2.2222,0.4908,,2.7130,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0,,0,0,,0,2.4408,,2.4408,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,1,0,,1,1,,2,0,,2,0.4444,,2.4444,3.5549,,5.9993,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,1,,0,1,,1,2,,0,2,,0.2222,2.2222,,0.4908,2.7130,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,0,0,,2.4408,2.4408,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,1,,0,1,,1,2,,0,2,,0.4444,2.4444,,3.5549,5.9993,,0 Residual surplus,0,,,0.0001,,,0.0001,,,0.0001,,,0.0001,,,0.0007,, diff --git a/src/test/resources/network/brightspots/rcv/test_data/test_set_overvote_delimiter/test_set_overvote_delimiter_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/test_set_overvote_delimiter/test_set_overvote_delimiter_expected_summary.csv index 63810e3..8155f2e 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/test_set_overvote_delimiter/test_set_overvote_delimiter_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/test_set_overvote_delimiter/test_set_overvote_delimiter_expected_summary.csv @@ -24,8 +24,8 @@ C,2,22.22%,0,2,25.0%,-2,0,0.0%,0 D,1,11.11%,-1,0,0.0%,0,0,0.0%,0 Active Ballots,9,,,8,,,8,, Current Round Threshold,5,,,5,,,5,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0, -Inactive Ballots Total,0,1,,1,0,,1,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,1,1,,0,1,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/test_set_treat_blank_as_undeclared_write_in/test_set_treat_blank_as_undeclared_write_in_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/test_set_treat_blank_as_undeclared_write_in/test_set_treat_blank_as_undeclared_write_in_expected_summary.csv index b6afcf8..7da15b2 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/test_set_treat_blank_as_undeclared_write_in/test_set_treat_blank_as_undeclared_write_in_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/test_set_treat_blank_as_undeclared_write_in/test_set_treat_blank_as_undeclared_write_in_expected_summary.csv @@ -25,8 +25,8 @@ D,1,8.33%,0,1,8.33%,-1,0,0.0%,0,0,0.0%,0,0,0.0%,0 Undeclared Write-ins,5,41.66%,-5,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 Active Ballots,12,,,12,,,12,,,12,,,9,, Current Round Threshold,7,,,7,,,7,,,7,,,5,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0,,0,1,,1,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0,,0,2,,2,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,0,0,,0,0,,0,0,,0,3,,3,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,1,1,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,2,2,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,0,0,,0,0,,0,0,,3,3,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/tiebreak_generate_permutation_test/tiebreak_generate_permutation_test_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/tiebreak_generate_permutation_test/tiebreak_generate_permutation_test_expected_summary.csv index e1ab234..f44c2a8 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/tiebreak_generate_permutation_test/tiebreak_generate_permutation_test_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/tiebreak_generate_permutation_test/tiebreak_generate_permutation_test_expected_summary.csv @@ -24,8 +24,8 @@ George Gervin,2,25.0%,0,2,33.33%,0,2,50.0%,0,2,100.0%,0 Mookie Blaylock,2,25.0%,-2,0,0.0%,0,0,0.0%,0,0,0.0%,0 Active Ballots,8,,,6,,,4,,,2,, Current Round Threshold,5,,,4,,,3,,,2,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,2,,2,2,,4,2,,6,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,0,2,,2,2,,4,2,,6,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,2,2,,2,4,,2,6,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,2,2,,2,4,,2,6,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/tiebreak_previous_round_counts_then_random_test/tiebreak_previous_round_counts_then_random_test_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/tiebreak_previous_round_counts_then_random_test/tiebreak_previous_round_counts_then_random_test_expected_summary.csv index 282007c..c4fb5ce 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/tiebreak_previous_round_counts_then_random_test/tiebreak_previous_round_counts_then_random_test_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/tiebreak_previous_round_counts_then_random_test/tiebreak_previous_round_counts_then_random_test_expected_summary.csv @@ -24,8 +24,8 @@ Grumpy,2,22.22%,1,3,33.33%,-3,0,0.0%,0,0,0.0%,0 Happy,1,11.11%,-1,0,0.0%,0,0,0.0%,0,0,0.0%,0 Active Ballots,9,,,9,,,6,,,3,, Current Round Threshold,5,,,5,,,4,,,2,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,0,0,,0,3,,3,3,,6,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,0,0,,3,3,,3,6,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/tiebreak_seed_test/tiebreak_seed_test_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/tiebreak_seed_test/tiebreak_seed_test_expected_summary.csv index ab75854..0063996 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/tiebreak_seed_test/tiebreak_seed_test_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/tiebreak_seed_test/tiebreak_seed_test_expected_summary.csv @@ -23,8 +23,8 @@ George Gervin,3,33.33%,0,3,50.0%,-3,0,0.0%,0 Mookie Blaylock,3,33.33%,0,3,50.0%,0,3,100.0%,0 Active Ballots,9,,,6,,,3,, Current Round Threshold,5,,,4,,,2,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0, -Inactive Ballots Total,0,3,,3,3,,6,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,3,3,,3,6,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/tiebreak_use_permutation_in_config_test/tiebreak_use_permutation_in_config_test_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/tiebreak_use_permutation_in_config_test/tiebreak_use_permutation_in_config_test_expected_summary.csv index c5da731..de8b753 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/tiebreak_use_permutation_in_config_test/tiebreak_use_permutation_in_config_test_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/tiebreak_use_permutation_in_config_test/tiebreak_use_permutation_in_config_test_expected_summary.csv @@ -24,8 +24,8 @@ George Gervin,2,20.0%,1,3,30.0%,-3,0,0.0%,0,0,0.0%,0 Sedale Threatt,1,10.0%,-1,0,0.0%,0,0,0.0%,0,0,0.0%,0 Active Ballots,10,,,10,,,8,,,4,, Current Round Threshold,6,,,6,,,5,,,3,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,0,0,,0,2,,2,4,,6,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,0,0,,2,2,,4,6,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_city_chief_of_police/unisyn_xml_cdf_city_chief_of_police_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_city_chief_of_police/unisyn_xml_cdf_city_chief_of_police_expected_summary.csv index 77fa139..74c755c 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_city_chief_of_police/unisyn_xml_cdf_city_chief_of_police_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_city_chief_of_police/unisyn_xml_cdf_city_chief_of_police_expected_summary.csv @@ -28,8 +28,8 @@ Emily Stevens,3,10.34%,0,3,10.34%,0,3,10.34%,-3,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0 Undeclared Write-ins,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 Active Ballots,29,,,29,,,29,,,29,,,29,,,29,,,25,, Current Round Threshold,15,,,15,,,15,,,15,,,15,,,15,,,13,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0,,0,0,,0,0,,0,4,,4,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,0,0,,0,0,,0,0,,0,0,,0,0,,0,4,,4,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,0,0,,0,0,,4,4,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,0,0,,0,0,,0,0,,0,0,,0,0,,4,4,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_city_coroner/unisyn_xml_cdf_city_coroner_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_city_coroner/unisyn_xml_cdf_city_coroner_expected_summary.csv index d6cadca..5e2fed2 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_city_coroner/unisyn_xml_cdf_city_coroner_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_city_coroner/unisyn_xml_cdf_city_coroner_expected_summary.csv @@ -27,8 +27,8 @@ Emily Van Zandt,3,10.34%,0,3,10.34%,0,3,10.34%,-3,0,0.0%,0,0,0.0%,0,0,0.0%,0 Undeclared Write-ins,1,3.44%,-1,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 Active Ballots,29,,,29,,,29,,,29,,,28,,,24,, Current Round Threshold,15,,,15,,,15,,,15,,,15,,,13,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0,,0,1,,1,4,,5,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,0,0,,0,0,,0,0,,0,1,,1,4,,5,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,1,1,,4,5,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,0,0,,0,0,,0,0,,1,1,,4,5,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_city_council_member/unisyn_xml_cdf_city_council_member_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_city_council_member/unisyn_xml_cdf_city_council_member_expected_summary.csv index 7026e2c..c85b2c1 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_city_council_member/unisyn_xml_cdf_city_council_member_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_city_council_member/unisyn_xml_cdf_city_council_member_expected_summary.csv @@ -29,8 +29,8 @@ Sylvia Vaugn,2,6.89%,0,2,6.89%,-2,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0 Undeclared Write-ins,1,3.44%,-1,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 Active Ballots,29,,,29,,,29,,,29,,,29,,,29,,,27,,,20,,,12,, Current Round Threshold,15,,,15,,,15,,,15,,,15,,,15,,,14,,,11,,,7,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0,,0,0,,0,0,,0,2,,2,7,,9,8,,17,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,0,0,,0,0,,0,0,,0,0,,0,0,,0,2,,2,7,,9,8,,17,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,0,0,,0,0,,2,2,,7,9,,8,17,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,0,0,,0,0,,0,0,,0,0,,0,0,,2,2,,7,9,,8,17,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_city_mayor/unisyn_xml_cdf_city_mayor_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_city_mayor/unisyn_xml_cdf_city_mayor_expected_summary.csv index 3ff0909..ba2dc82 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_city_mayor/unisyn_xml_cdf_city_mayor_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_city_mayor/unisyn_xml_cdf_city_mayor_expected_summary.csv @@ -33,8 +33,8 @@ Carrol Wilson,1,3.44%,0,1,3.44%,0,1,3.44%,-1,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 Undeclared Write-ins,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 Active Ballots,29,,,29,,,29,,,29,,,29,,,29,,,29,,,29,,,27,,,24,,,21,,,16,, Current Round Threshold,15,,,15,,,15,,,15,,,15,,,15,,,15,,,15,,,14,,,13,,,11,,,9,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,2,,2,3,,5,3,,8,5,,13,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,2,,2,3,,5,3,,8,5,,13,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,2,2,,3,5,,3,8,,5,13,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,2,2,,3,5,,3,8,,5,13,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_city_tax_collector/unisyn_xml_cdf_city_tax_collector_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_city_tax_collector/unisyn_xml_cdf_city_tax_collector_expected_summary.csv index 65dc432..42e27ed 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_city_tax_collector/unisyn_xml_cdf_city_tax_collector_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_city_tax_collector/unisyn_xml_cdf_city_tax_collector_expected_summary.csv @@ -29,8 +29,8 @@ Brady Gordon,2,6.89%,1,3,10.34%,0,3,10.34%,0,3,10.34%,-3,0,0.0%,0,0,0.0%,0,0,0.0 Undeclared Write-ins,1,3.44%,-1,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 Active Ballots,29,,,29,,,29,,,29,,,29,,,29,,,28,,,25,, Current Round Threshold,15,,,15,,,15,,,15,,,15,,,15,,,15,,,13,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0,,0,0,,0,0,,0,1,,1,3,,4,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,0,0,,0,0,,0,0,,0,0,,0,0,,0,1,,1,3,,4,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,0,0,,0,0,,1,1,,3,4,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,0,0,,0,0,,0,0,,0,0,,0,0,,1,1,,3,4,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_county_coroner/unisyn_xml_cdf_county_coroner_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_county_coroner/unisyn_xml_cdf_county_coroner_expected_summary.csv index 697d206..495c196 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_county_coroner/unisyn_xml_cdf_county_coroner_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_county_coroner/unisyn_xml_cdf_county_coroner_expected_summary.csv @@ -29,8 +29,8 @@ Walter Gerber,3,10.34%,0,3,10.34%,1,4,13.79%,0,4,13.79%,0,4,13.79%,-4,0,0.0%,0,0 Undeclared Write-ins,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 Active Ballots,29,,,29,,,29,,,29,,,29,,,25,,,24,,,18,,,9,, Current Round Threshold,15,,,15,,,15,,,15,,,15,,,13,,,13,,,10,,,5,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0,,0,0,,0,4,,4,1,,5,6,,11,9,,20,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,0,0,,0,0,,0,0,,0,0,,0,4,,4,1,,5,6,,11,9,,20,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,0,0,,4,4,,1,5,,6,11,,9,20,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,0,0,,0,0,,0,0,,0,0,,4,4,,1,5,,6,11,,9,20,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_county_sheriff/unisyn_xml_cdf_county_sheriff_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_county_sheriff/unisyn_xml_cdf_county_sheriff_expected_summary.csv index 8a4b629..a05d552 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_county_sheriff/unisyn_xml_cdf_county_sheriff_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_county_sheriff/unisyn_xml_cdf_county_sheriff_expected_summary.csv @@ -28,8 +28,8 @@ Beth Small,2,6.89%,0,2,6.89%,-2,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0 Undeclared Write-ins,2,6.89%,-2,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 Active Ballots,29,,,29,,,29,,,29,,,29,,,29,,,24,,,17,, Current Round Threshold,15,,,15,,,15,,,15,,,15,,,15,,,13,,,9,, -Inactive Ballots by by Overvotes,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,0,,0,0,,0,0,,0,0,,0,0,,0,5,,5,7,,12,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0, -Inactive Ballots Total,0,0,,0,0,,0,0,,0,0,,0,0,,0,5,,5,7,,12,0, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,0,0,,0,0,,5,5,,7,12,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,0,0,,0,0,,0,0,,0,0,,0,0,,5,5,,7,12,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/uwi_cannot_win_test/uwi_cannot_win_test_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/uwi_cannot_win_test/uwi_cannot_win_test_expected_summary.csv index d883ef1..42f603b 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/uwi_cannot_win_test/uwi_cannot_win_test_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/uwi_cannot_win_test/uwi_cannot_win_test_expected_summary.csv @@ -23,8 +23,8 @@ B,1,11.11%,0,1,25.0%,0 Undeclared Write-ins,5,55.55%,-5,0,0.0%,0 Active Ballots,9,,,4,, Current Round Threshold,5,,,3,, -Inactive Ballots by by Overvotes,0,0,,0,0, -Inactive Ballots by by Skipped Rankings,0,0,,0,0, -Inactive Ballots by by Exhausted Choices,0,5,,5,0, -Inactive Ballots by by Repeated Rankings,0,0,,0,0, -Inactive Ballots Total,0,5,,5,0, +Inactive Ballots by Overvotes,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,5,5,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0 +Inactive Ballots Total,0,,5,5,,0
https://github.com/BrightSpots/rcv.gitdiff --git a/src/main/java/network/brightspots/rcv/ResultsWriter.java b/src/main/java/network/brightspots/rcv/ResultsWriter.java
gitbug-java_data_BrightSpots-rcv.json_3
diff --git a/src/main/java/network/brightspots/rcv/Tabulator.java b/src/main/java/network/brightspots/rcv/Tabulator.java index c319cfa..c957a09 100644 --- a/src/main/java/network/brightspots/rcv/Tabulator.java +++ b/src/main/java/network/brightspots/rcv/Tabulator.java @@ -520,9 +520,9 @@ class Tabulator { } } else { // We should only look for more winners if we haven't already filled all the seats. - if (winnerToRound.size() < config.getNumberOfWinners()) { - if (currentRoundTally.numActiveCandidates() - == config.getNumberOfWinners() - winnerToRound.size()) { + int numSeatsUnfilled = config.getNumberOfWinners() - winnerToRound.size(); + if (numSeatsUnfilled > 0) { + if (currentRoundTally.numActiveCandidates() == numSeatsUnfilled) { // If the number of continuing candidates equals the number of seats to fill, // everyone wins. selectedWinners.addAll(currentRoundTally.getCandidates()); @@ -548,9 +548,25 @@ class Tabulator { // * If this is a single-winner election in which it's possible for no candidate to reach the // threshold (i.e. "first round determines threshold" is set), the tiebreaker will choose // the only winner. - boolean useTiebreakerIfNeeded = config.isMultiSeatAllowOnlyOneWinnerPerRoundEnabled() - || config.isFirstRoundDeterminesThresholdEnabled(); - if (useTiebreakerIfNeeded && selectedWinners.size() > 1) { + boolean needsTiebreakMultipleWinners = selectedWinners.size() > 1 + && (config.isMultiSeatAllowOnlyOneWinnerPerRoundEnabled() + || config.isFirstRoundDeterminesThresholdEnabled()); + // Edge case: there are two candidates remaining. To avoid having just one candidate in the + // final round, we break the tie here. Happens when we have unfilled seats, two candidates + // remaining, neither meets the threshold, and both have more than the minimum vote threshold. + // Conditions: + // 1. Single-winner election + // 2. There are two remaining candidates + // 3. There is one seat unfilled (i.e. the seat hasn't already been filled in a previous + // round due to "Continue Untli Two Remain" config option) + // 4. All candidates are over the minimum threshold (see no_one_meets_minimum test) + boolean needsTiebreakNoWinners = config.getNumberOfWinners() == 1 + && selectedWinners.size() == 0 + && currentRoundTally.numActiveCandidates() == 2 + && numSeatsUnfilled == 1 + && currentRoundTallyToCandidates.keySet().stream().allMatch( + x -> x.compareTo(config.getMinimumVoteThreshold()) >= 0); + if (needsTiebreakMultipleWinners || needsTiebreakNoWinners) { // currentRoundTallyToCandidates is sorted from low to high, so just look at the last key BigDecimal maxVotes = currentRoundTallyToCandidates.lastKey(); selectedWinners = currentRoundTallyToCandidates.get(maxVotes); diff --git a/src/test/resources/network/brightspots/rcv/test_data/missing_precinct_example/missing_precinct_example_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/missing_precinct_example/missing_precinct_example_expected_summary.csv index 2bc4497..a6c86c7 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/missing_precinct_example/missing_precinct_example_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/missing_precinct_example/missing_precinct_example_expected_summary.csv @@ -7,7 +7,7 @@ Jurisdiction,"Minneapolis, MN" Office,Mayor Date,2017-11-07 Winner(s),Jacob Frey -Final Threshold,2 +Final Threshold,3 Contest Summary Number to be Elected,1 @@ -15,32 +15,32 @@ Number of Candidates,19 Total Number of Ballots,4 Number of Undervotes,0 -Rounds,Round 1 Votes,% of vote,transfer,Round 2 Votes,% of vote,transfer,Round 3 Votes,% of vote,transfer,Round 4 Votes,% of vote,transfer,Round 5 Votes,% of vote,transfer -Eliminated,Aswar Rahman; David Rosenfeld; Raymond Dehn; L.A. Nik; Undeclared Write-ins; Christopher Zimmerman; Ronald Lischeid; Ian Simpson; Charlie Gers; Captain Jack Sparrow; Theron Preston Washington; David John Wilson; Gregg A. Iverson; Troy Benjegerdes; Al Flowers,,,Nekima Levy-Pounds,,,Tom Hoch,,,Betsy Hodges,,,,, -Elected,,,,,,,,,,,,,Jacob Frey,, -Tom Hoch,1,25.0%,0,1,25.0%,0,1,25.0%,-1,0,0.0%,0,0,0.0%,0 -Betsy Hodges,1,25.0%,0,1,25.0%,1,2,50.0%,0,2,50.0%,-2,0,0.0%,0 -Jacob Frey,1,25.0%,0,1,25.0%,0,1,25.0%,1,2,50.0%,0,2,100.0%,0 -Nekima Levy-Pounds,1,25.0%,0,1,25.0%,-1,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Aswar Rahman,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 -David Rosenfeld,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Raymond Dehn,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 -L.A. Nik,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Christopher Zimmerman,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Ronald Lischeid,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Ian Simpson,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Charlie Gers,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Captain Jack Sparrow,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Theron Preston Washington,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 -David John Wilson,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Gregg A. Iverson,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Troy Benjegerdes,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Al Flowers,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Undeclared Write-ins,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Active Ballots,4,,,4,,,4,,,4,,,2,, -Current Round Threshold,3,,,3,,,3,,,3,,,2,, -Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0,0,,0 -Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0,0,,0 -Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,2,2,,0 -Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0 -Inactive Ballots Total,0,,0,0,,0,0,,0,0,,2,2,,0 +Rounds,Round 1 Votes,% of vote,transfer,Round 2 Votes,% of vote,transfer,Round 3 Votes,% of vote,transfer,Round 4 Votes,% of vote,transfer +Eliminated,Aswar Rahman; David Rosenfeld; Raymond Dehn; L.A. Nik; Undeclared Write-ins; Christopher Zimmerman; Ronald Lischeid; Ian Simpson; Charlie Gers; Captain Jack Sparrow; Theron Preston Washington; David John Wilson; Gregg A. Iverson; Troy Benjegerdes; Al Flowers,,,Nekima Levy-Pounds,,,Tom Hoch,,,,, +Elected,,,,,,,,,,Jacob Frey,, +Tom Hoch,1,25.0%,0,1,25.0%,0,1,25.0%,-1,0,0.0%,0 +Betsy Hodges,1,25.0%,0,1,25.0%,1,2,50.0%,0,2,50.0%,0 +Jacob Frey,1,25.0%,0,1,25.0%,0,1,25.0%,1,2,50.0%,0 +Nekima Levy-Pounds,1,25.0%,0,1,25.0%,-1,0,0.0%,0,0,0.0%,0 +Aswar Rahman,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 +David Rosenfeld,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 +Raymond Dehn,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 +L.A. Nik,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 +Christopher Zimmerman,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 +Ronald Lischeid,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 +Ian Simpson,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 +Charlie Gers,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 +Captain Jack Sparrow,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 +Theron Preston Washington,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 +David John Wilson,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 +Gregg A. Iverson,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 +Troy Benjegerdes,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 +Al Flowers,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 +Undeclared Write-ins,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 +Active Ballots,4,,,4,,,4,,,4,, +Current Round Threshold,3,,,3,,,3,,,3,, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,0,0,,0,0,,0,0,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/missing_precinct_example/missing_precinct_example_expected_summary.json b/src/test/resources/network/brightspots/rcv/test_data/missing_precinct_example/missing_precinct_example_expected_summary.json index ae3b5dd..c25dea1 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/missing_precinct_example/missing_precinct_example_expected_summary.json +++ b/src/test/resources/network/brightspots/rcv/test_data/missing_precinct_example/missing_precinct_example_expected_summary.json @@ -137,31 +137,13 @@ "Jacob Frey" : "2" }, "tallyResults" : [ { - "eliminated" : "Betsy Hodges", - "transfers" : { - "exhausted" : "2" - } - } ], - "threshold" : "3" - }, { - "inactiveBallots" : { - "exhaustedChoices" : "2", - "overvotes" : "0", - "repeatedRankings" : "0", - "skippedRankings" : "0" - }, - "round" : 5, - "tally" : { - "Jacob Frey" : "2" - }, - "tallyResults" : [ { "elected" : "Jacob Frey", "transfers" : { } } ], - "threshold" : "2" + "threshold" : "3" } ], "summary" : { - "finalThreshold" : "2", + "finalThreshold" : "3", "numCandidates" : 19, "numWinners" : 1, "totalNumBallots" : "4", diff --git a/src/test/resources/network/brightspots/rcv/test_data/nist_xml_cdf_2/nist_xml_cdf_2_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/nist_xml_cdf_2/nist_xml_cdf_2_expected_summary.csv index d93f9ce..e0398f4 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/nist_xml_cdf_2/nist_xml_cdf_2_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/nist_xml_cdf_2/nist_xml_cdf_2_expected_summary.csv @@ -6,7 +6,7 @@ Contest,For Governor and Lieutenant Governor Jurisdiction, Office, Date,2019-03-06 -Winner(s),Edward FitzGerald and Sharen Swartz Neuhardt +Winner(s),Anita Rios and Bob Fitrakis Final Threshold,1 Contest Summary @@ -15,16 +15,16 @@ Number of Candidates,3 Total Number of Ballots,1 Number of Undervotes,1 -Rounds,Round 1 Votes,% of vote,transfer,Round 2 Votes,% of vote,transfer,Round 3 Votes,% of vote,transfer -Eliminated,John Kasich and Mary Taylor,,,Anita Rios and Bob Fitrakis,,,,, -Elected,,,,,,,Edward FitzGerald and Sharen Swartz Neuhardt,, -Edward FitzGerald and Sharen Swartz Neuhardt,0,,0,0,,0,0,,0 -John Kasich and Mary Taylor,0,,0,0,,0,0,,0 -Anita Rios and Bob Fitrakis,0,,0,0,,0,0,,0 -Active Ballots,0,,,0,,,0,, -Current Round Threshold,1,,,1,,,1,, -Inactive Ballots by Overvotes,0,,0,0,,0,0,,0 -Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0 -Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0 -Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0 -Inactive Ballots Total,0,,0,0,,0,0,,0 +Rounds,Round 1 Votes,% of vote,transfer,Round 2 Votes,% of vote,transfer +Eliminated,John Kasich and Mary Taylor,,,,, +Elected,,,,Anita Rios and Bob Fitrakis,, +Edward FitzGerald and Sharen Swartz Neuhardt,0,,0,0,,0 +John Kasich and Mary Taylor,0,,0,0,,0 +Anita Rios and Bob Fitrakis,0,,0,0,,0 +Active Ballots,0,,,0,, +Current Round Threshold,1,,,1,, +Inactive Ballots by Overvotes,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0 +Inactive Ballots Total,0,,0,0,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/nist_xml_cdf_2/nist_xml_cdf_2_expected_summary.json b/src/test/resources/network/brightspots/rcv/test_data/nist_xml_cdf_2/nist_xml_cdf_2_expected_summary.json index e7594ab..428ea31 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/nist_xml_cdf_2/nist_xml_cdf_2_expected_summary.json +++ b/src/test/resources/network/brightspots/rcv/test_data/nist_xml_cdf_2/nist_xml_cdf_2_expected_summary.json @@ -38,23 +38,7 @@ "Edward FitzGerald and Sharen Swartz Neuhardt" : "0" }, "tallyResults" : [ { - "eliminated" : "Anita Rios and Bob Fitrakis", - "transfers" : { } - } ], - "threshold" : "1" - }, { - "inactiveBallots" : { - "exhaustedChoices" : "0", - "overvotes" : "0", - "repeatedRankings" : "0", - "skippedRankings" : "0" - }, - "round" : 3, - "tally" : { - "Edward FitzGerald and Sharen Swartz Neuhardt" : "0" - }, - "tallyResults" : [ { - "elected" : "Edward FitzGerald and Sharen Swartz Neuhardt", + "elected" : "Anita Rios and Bob Fitrakis", "transfers" : { } } ], "threshold" : "1" diff --git a/src/test/resources/network/brightspots/rcv/test_data/sequential_with_batch/sequential_with_batch_2_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/sequential_with_batch/sequential_with_batch_2_expected_summary.csv index 1bc914c..15275fc 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/sequential_with_batch/sequential_with_batch_2_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/sequential_with_batch/sequential_with_batch_2_expected_summary.csv @@ -7,7 +7,7 @@ Jurisdiction, Office, Date, Winner(s),B -Final Threshold,2 +Final Threshold,3 Contest Summary Number to be Elected,1 @@ -15,18 +15,18 @@ Number of Candidates,5 Total Number of Ballots,9 Number of Undervotes,0 -Rounds,Round 1 Votes,% of vote,transfer,Round 2 Votes,% of vote,transfer,Round 3 Votes,% of vote,transfer -Eliminated,D; E; F,,,C,,,,, -Elected,,,,,,,B,, -B,2,40.0%,0,2,50.0%,0,2,100.0%,0 -C,2,40.0%,0,2,50.0%,-2,0,0.0%,0 -D,1,20.0%,-1,0,0.0%,0,0,0.0%,0 -E,0,0.0%,0,0,0.0%,0,0,0.0%,0 -F,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Active Ballots,5,,,4,,,2,, -Current Round Threshold,3,,,3,,,2,, -Inactive Ballots by Overvotes,0,,0,0,,0,0,,0 -Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0 -Inactive Ballots by Exhausted Choices,4,,1,5,,2,7,,0 -Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0 -Inactive Ballots Total,4,,1,5,,2,7,,0 +Rounds,Round 1 Votes,% of vote,transfer,Round 2 Votes,% of vote,transfer +Eliminated,D; E; F,,,,, +Elected,,,,B,, +B,2,40.0%,0,2,50.0%,0 +C,2,40.0%,0,2,50.0%,0 +D,1,20.0%,-1,0,0.0%,0 +E,0,0.0%,0,0,0.0%,0 +F,0,0.0%,0,0,0.0%,0 +Active Ballots,5,,,4,, +Current Round Threshold,3,,,3,, +Inactive Ballots by Overvotes,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,4,,1,5,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0 +Inactive Ballots Total,4,,1,5,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/sequential_with_batch/sequential_with_batch_2_expected_summary.json b/src/test/resources/network/brightspots/rcv/test_data/sequential_with_batch/sequential_with_batch_2_expected_summary.json index bbf8a8f..5392339 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/sequential_with_batch/sequential_with_batch_2_expected_summary.json +++ b/src/test/resources/network/brightspots/rcv/test_data/sequential_with_batch/sequential_with_batch_2_expected_summary.json @@ -48,31 +48,13 @@ "C" : "2" }, "tallyResults" : [ { - "eliminated" : "C", - "transfers" : { - "exhausted" : "2" - } - } ], - "threshold" : "3" - }, { - "inactiveBallots" : { - "exhaustedChoices" : "7", - "overvotes" : "0", - "repeatedRankings" : "0", - "skippedRankings" : "0" - }, - "round" : 3, - "tally" : { - "B" : "2" - }, - "tallyResults" : [ { "elected" : "B", "transfers" : { } } ], - "threshold" : "2" + "threshold" : "3" } ], "summary" : { - "finalThreshold" : "2", + "finalThreshold" : "3", "numCandidates" : 6, "numWinners" : 1, "totalNumBallots" : "9", diff --git a/src/test/resources/network/brightspots/rcv/test_data/sequential_with_continue_until_two/sequential_with_continue_until_two_2_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/sequential_with_continue_until_two/sequential_with_continue_until_two_2_expected_summary.csv index 205bd26..d6b20ec 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/sequential_with_continue_until_two/sequential_with_continue_until_two_2_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/sequential_with_continue_until_two/sequential_with_continue_until_two_2_expected_summary.csv @@ -7,7 +7,7 @@ Jurisdiction, Office, Date, Winner(s),B -Final Threshold,2 +Final Threshold,3 Contest Summary Number to be Elected,1 @@ -15,18 +15,18 @@ Number of Candidates,5 Total Number of Ballots,9 Number of Undervotes,0 -Rounds,Round 1 Votes,% of vote,transfer,Round 2 Votes,% of vote,transfer,Round 3 Votes,% of vote,transfer,Round 4 Votes,% of vote,transfer,Round 5 Votes,% of vote,transfer -Eliminated,F,,,E,,,D,,,C,,,,, -Elected,,,,,,,,,,,,,B,, -B,2,40.0%,0,2,40.0%,0,2,40.0%,0,2,50.0%,0,2,100.0%,0 -C,2,40.0%,0,2,40.0%,0,2,40.0%,0,2,50.0%,-2,0,0.0%,0 -D,1,20.0%,0,1,20.0%,0,1,20.0%,-1,0,0.0%,0,0,0.0%,0 -E,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 -F,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Active Ballots,5,,,5,,,5,,,4,,,2,, -Current Round Threshold,3,,,3,,,3,,,3,,,2,, -Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0,0,,0 -Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0,0,,0 -Inactive Ballots by Exhausted Choices,4,,0,4,,0,4,,1,5,,2,7,,0 -Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0 -Inactive Ballots Total,4,,0,4,,0,4,,1,5,,2,7,,0 +Rounds,Round 1 Votes,% of vote,transfer,Round 2 Votes,% of vote,transfer,Round 3 Votes,% of vote,transfer,Round 4 Votes,% of vote,transfer +Eliminated,F,,,E,,,D,,,,, +Elected,,,,,,,,,,B,, +B,2,40.0%,0,2,40.0%,0,2,40.0%,0,2,50.0%,0 +C,2,40.0%,0,2,40.0%,0,2,40.0%,0,2,50.0%,0 +D,1,20.0%,0,1,20.0%,0,1,20.0%,-1,0,0.0%,0 +E,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 +F,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 +Active Ballots,5,,,5,,,5,,,4,, +Current Round Threshold,3,,,3,,,3,,,3,, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,4,,0,4,,0,4,,1,5,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,4,,0,4,,0,4,,1,5,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/sequential_with_continue_until_two/sequential_with_continue_until_two_2_expected_summary.json b/src/test/resources/network/brightspots/rcv/test_data/sequential_with_continue_until_two/sequential_with_continue_until_two_2_expected_summary.json index a8c553d..809e32d 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/sequential_with_continue_until_two/sequential_with_continue_until_two_2_expected_summary.json +++ b/src/test/resources/network/brightspots/rcv/test_data/sequential_with_continue_until_two/sequential_with_continue_until_two_2_expected_summary.json @@ -79,31 +79,13 @@ "C" : "2" }, "tallyResults" : [ { - "eliminated" : "C", - "transfers" : { - "exhausted" : "2" - } - } ], - "threshold" : "3" - }, { - "inactiveBallots" : { - "exhaustedChoices" : "7", - "overvotes" : "0", - "repeatedRankings" : "0", - "skippedRankings" : "0" - }, - "round" : 5, - "tally" : { - "B" : "2" - }, - "tallyResults" : [ { "elected" : "B", "transfers" : { } } ], - "threshold" : "2" + "threshold" : "3" } ], "summary" : { - "finalThreshold" : "2", + "finalThreshold" : "3", "numCandidates" : 6, "numWinners" : 1, "totalNumBallots" : "9", diff --git a/src/test/resources/network/brightspots/rcv/test_data/stop_tabulation_early_test/stop_tabulation_early_test_config.json b/src/test/resources/network/brightspots/rcv/test_data/stop_tabulation_early_test/stop_tabulation_early_test_config.json index e69cb7b..58fbc65 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/stop_tabulation_early_test/stop_tabulation_early_test_config.json +++ b/src/test/resources/network/brightspots/rcv/test_data/stop_tabulation_early_test/stop_tabulation_early_test_config.json @@ -50,6 +50,6 @@ "batchElimination": true, "exhaustOnDuplicateCandidate": false, "rulesDescription": "Doyle Rules", - "stopTabulationEarlyAfterRound": "2" + "stopTabulationEarlyAfterRound": "1" } } diff --git a/src/test/resources/network/brightspots/rcv/test_data/stop_tabulation_early_test/stop_tabulation_early_test_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/stop_tabulation_early_test/stop_tabulation_early_test_expected_summary.csv index f1e7343..e462a09 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/stop_tabulation_early_test/stop_tabulation_early_test_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/stop_tabulation_early_test/stop_tabulation_early_test_expected_summary.csv @@ -7,7 +7,7 @@ Jurisdiction,"Funkytown, USA" Office,Sergeant-at-Arms Date,2023-03-14 Winner(s), -Final Threshold,4 +Final Threshold,5 Contest Summary Number to be Elected,1 @@ -15,16 +15,16 @@ Number of Candidates,3 Total Number of Ballots,9 Number of Undervotes,0 -Rounds,Round 1 Votes,% of vote,transfer,Round 2 Votes,% of vote,transfer -Eliminated,Yinka Dare,,,George Gervin,, -Elected,,,,,, -Yinka Dare,3,33.33%,-3,0,0.0%,0 -George Gervin,3,33.33%,0,3,50.0%,0 -Mookie Blaylock,3,33.33%,0,3,50.0%,0 -Active Ballots,9,,,6,, -Current Round Threshold,5,,,4,, -Inactive Ballots by Overvotes,0,,0,0,,0 -Inactive Ballots by Skipped Rankings,0,,0,0,,0 -Inactive Ballots by Exhausted Choices,0,,0,0,,0 -Inactive Ballots by Repeated Rankings,0,,0,0,,0 -Inactive Ballots Total,0,,3,3,,0 +Rounds,Round 1 Votes,% of vote,transfer +Eliminated,Yinka Dare,, +Elected,,, +Yinka Dare,3,33.33%,0 +George Gervin,3,33.33%,0 +Mookie Blaylock,3,33.33%,0 +Active Ballots,9,, +Current Round Threshold,5,, +Inactive Ballots by Overvotes,0,,0 +Inactive Ballots by Skipped Rankings,0,,0 +Inactive Ballots by Exhausted Choices,0,,0 +Inactive Ballots by Repeated Rankings,0,,0 +Inactive Ballots Total,0,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/stop_tabulation_early_test/stop_tabulation_early_test_expected_summary.json b/src/test/resources/network/brightspots/rcv/test_data/stop_tabulation_early_test/stop_tabulation_early_test_expected_summary.json index 48a8f43..3e9c40b 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/stop_tabulation_early_test/stop_tabulation_early_test_expected_summary.json +++ b/src/test/resources/network/brightspots/rcv/test_data/stop_tabulation_early_test/stop_tabulation_early_test_expected_summary.json @@ -22,31 +22,12 @@ }, "tallyResults" : [ { "eliminated" : "Yinka Dare", - "transfers" : { - "exhausted" : "3" - } - } ], - "threshold" : "5" - }, { - "inactiveBallots" : { - "exhaustedChoices" : "0", - "overvotes" : "0", - "repeatedRankings" : "0", - "skippedRankings" : "0" - }, - "round" : 2, - "tally" : { - "George Gervin" : "3", - "Mookie Blaylock" : "3" - }, - "tallyResults" : [ { - "eliminated" : "George Gervin", "transfers" : { } } ], - "threshold" : "4" + "threshold" : "5" } ], "summary" : { - "finalThreshold" : "4", + "finalThreshold" : "5", "numCandidates" : 3, "numWinners" : 1, "totalNumBallots" : "9", diff --git a/src/test/resources/network/brightspots/rcv/test_data/test_set_treat_blank_as_undeclared_write_in/test_set_treat_blank_as_undeclared_write_in_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/test_set_treat_blank_as_undeclared_write_in/test_set_treat_blank_as_undeclared_write_in_expected_summary.csv index 7da15b2..fc3a7ae 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/test_set_treat_blank_as_undeclared_write_in/test_set_treat_blank_as_undeclared_write_in_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/test_set_treat_blank_as_undeclared_write_in/test_set_treat_blank_as_undeclared_write_in_expected_summary.csv @@ -6,8 +6,8 @@ Contest,treatBlankAsUndeclaredWriteIn test Jurisdiction, Office, Date,2019-03-06 -Winner(s),B -Final Threshold,5 +Winner(s),C +Final Threshold,7 Contest Summary Number to be Elected,1 @@ -15,18 +15,18 @@ Number of Candidates,5 Total Number of Ballots,12 Number of Undervotes,0 -Rounds,Round 1 Votes,% of vote,transfer,Round 2 Votes,% of vote,transfer,Round 3 Votes,% of vote,transfer,Round 4 Votes,% of vote,transfer,Round 5 Votes,% of vote,transfer -Eliminated,Undeclared Write-ins,,,D,,,A,,,C,,,,, -Elected,,,,,,,,,,,,,B,, -A,2,16.66%,1,3,25.0%,0,3,25.0%,-3,0,0.0%,0,0,0.0%,0 -B,2,16.66%,2,4,33.33%,1,5,41.66%,1,6,50.0%,3,9,100.0%,0 -C,2,16.66%,2,4,33.33%,0,4,33.33%,2,6,50.0%,-6,0,0.0%,0 -D,1,8.33%,0,1,8.33%,-1,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Undeclared Write-ins,5,41.66%,-5,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Active Ballots,12,,,12,,,12,,,12,,,9,, -Current Round Threshold,7,,,7,,,7,,,7,,,5,, -Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,1,1,,0 -Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0,0,,0 -Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,2,2,,0 -Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0 -Inactive Ballots Total,0,,0,0,,0,0,,0,0,,3,3,,0 +Rounds,Round 1 Votes,% of vote,transfer,Round 2 Votes,% of vote,transfer,Round 3 Votes,% of vote,transfer,Round 4 Votes,% of vote,transfer +Eliminated,Undeclared Write-ins,,,D,,,A,,,,, +Elected,,,,,,,,,,C,, +A,2,16.66%,1,3,25.0%,0,3,25.0%,-3,0,0.0%,0 +B,2,16.66%,2,4,33.33%,1,5,41.66%,1,6,50.0%,0 +C,2,16.66%,2,4,33.33%,0,4,33.33%,2,6,50.0%,0 +D,1,8.33%,0,1,8.33%,-1,0,0.0%,0,0,0.0%,0 +Undeclared Write-ins,5,41.66%,-5,0,0.0%,0,0,0.0%,0,0,0.0%,0 +Active Ballots,12,,,12,,,12,,,12,, +Current Round Threshold,7,,,7,,,7,,,7,, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,0,0,,0,0,,0,0,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/test_set_treat_blank_as_undeclared_write_in/test_set_treat_blank_as_undeclared_write_in_expected_summary.json b/src/test/resources/network/brightspots/rcv/test_data/test_set_treat_blank_as_undeclared_write_in/test_set_treat_blank_as_undeclared_write_in_expected_summary.json index 25e4d0b..7c409e5 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/test_set_treat_blank_as_undeclared_write_in/test_set_treat_blank_as_undeclared_write_in_expected_summary.json +++ b/src/test/resources/network/brightspots/rcv/test_data/test_set_treat_blank_as_undeclared_write_in/test_set_treat_blank_as_undeclared_write_in_expected_summary.json @@ -86,32 +86,13 @@ "C" : "6" }, "tallyResults" : [ { - "eliminated" : "C", - "transfers" : { - "B" : "3", - "exhausted" : "3" - } - } ], - "threshold" : "7" - }, { - "inactiveBallots" : { - "exhaustedChoices" : "2", - "overvotes" : "1", - "repeatedRankings" : "0", - "skippedRankings" : "0" - }, - "round" : 5, - "tally" : { - "B" : "9" - }, - "tallyResults" : [ { - "elected" : "B", + "elected" : "C", "transfers" : { } } ], - "threshold" : "5" + "threshold" : "7" } ], "summary" : { - "finalThreshold" : "5", + "finalThreshold" : "7", "numCandidates" : 5, "numWinners" : 1, "totalNumBallots" : "12", diff --git a/src/test/resources/network/brightspots/rcv/test_data/tiebreak_generate_permutation_test/tiebreak_generate_permutation_test_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/tiebreak_generate_permutation_test/tiebreak_generate_permutation_test_expected_summary.csv index f44c2a8..80b9ab5 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/tiebreak_generate_permutation_test/tiebreak_generate_permutation_test_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/tiebreak_generate_permutation_test/tiebreak_generate_permutation_test_expected_summary.csv @@ -7,7 +7,7 @@ Jurisdiction,"Funkytown, USA" Office,Sergeant-at-Arms Date,2017-12-03 Winner(s),George Gervin -Final Threshold,2 +Final Threshold,3 Contest Summary Number to be Elected,1 @@ -15,17 +15,17 @@ Number of Candidates,4 Total Number of Ballots,8 Number of Undervotes,0 -Rounds,Round 1 Votes,% of vote,transfer,Round 2 Votes,% of vote,transfer,Round 3 Votes,% of vote,transfer,Round 4 Votes,% of vote,transfer -Eliminated,Mookie Blaylock,,,Yinka Dare,,,Sedale Threatt,,,,, -Elected,,,,,,,,,,George Gervin,, -Sedale Threatt,2,25.0%,0,2,33.33%,0,2,50.0%,-2,0,0.0%,0 -Yinka Dare,2,25.0%,0,2,33.33%,-2,0,0.0%,0,0,0.0%,0 -George Gervin,2,25.0%,0,2,33.33%,0,2,50.0%,0,2,100.0%,0 -Mookie Blaylock,2,25.0%,-2,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Active Ballots,8,,,6,,,4,,,2,, -Current Round Threshold,5,,,4,,,3,,,2,, -Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0 -Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0 -Inactive Ballots by Exhausted Choices,0,,2,2,,2,4,,2,6,,0 -Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0 -Inactive Ballots Total,0,,2,2,,2,4,,2,6,,0 +Rounds,Round 1 Votes,% of vote,transfer,Round 2 Votes,% of vote,transfer,Round 3 Votes,% of vote,transfer +Eliminated,Mookie Blaylock,,,Yinka Dare,,,,, +Elected,,,,,,,George Gervin,, +Sedale Threatt,2,25.0%,0,2,33.33%,0,2,50.0%,0 +Yinka Dare,2,25.0%,0,2,33.33%,-2,0,0.0%,0 +George Gervin,2,25.0%,0,2,33.33%,0,2,50.0%,0 +Mookie Blaylock,2,25.0%,-2,0,0.0%,0,0,0.0%,0 +Active Ballots,8,,,6,,,4,, +Current Round Threshold,5,,,4,,,3,, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,2,2,,2,4,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,2,2,,2,4,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/tiebreak_generate_permutation_test/tiebreak_generate_permutation_test_expected_summary.json b/src/test/resources/network/brightspots/rcv/test_data/tiebreak_generate_permutation_test/tiebreak_generate_permutation_test_expected_summary.json index 5dac64a..a4303b8 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/tiebreak_generate_permutation_test/tiebreak_generate_permutation_test_expected_summary.json +++ b/src/test/resources/network/brightspots/rcv/test_data/tiebreak_generate_permutation_test/tiebreak_generate_permutation_test_expected_summary.json @@ -61,31 +61,13 @@ "Sedale Threatt" : "2" }, "tallyResults" : [ { - "eliminated" : "Sedale Threatt", - "transfers" : { - "exhausted" : "2" - } - } ], - "threshold" : "3" - }, { - "inactiveBallots" : { - "exhaustedChoices" : "6", - "overvotes" : "0", - "repeatedRankings" : "0", - "skippedRankings" : "0" - }, - "round" : 4, - "tally" : { - "George Gervin" : "2" - }, - "tallyResults" : [ { "elected" : "George Gervin", "transfers" : { } } ], - "threshold" : "2" + "threshold" : "3" } ], "summary" : { - "finalThreshold" : "2", + "finalThreshold" : "3", "numCandidates" : 4, "numWinners" : 1, "totalNumBallots" : "8", diff --git a/src/test/resources/network/brightspots/rcv/test_data/tiebreak_previous_round_counts_then_random_test/tiebreak_previous_round_counts_then_random_test_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/tiebreak_previous_round_counts_then_random_test/tiebreak_previous_round_counts_then_random_test_expected_summary.csv index c4fb5ce..2775757 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/tiebreak_previous_round_counts_then_random_test/tiebreak_previous_round_counts_then_random_test_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/tiebreak_previous_round_counts_then_random_test/tiebreak_previous_round_counts_then_random_test_expected_summary.csv @@ -6,8 +6,8 @@ Contest,Tiebreak test Jurisdiction,"Funkytown, USA" Office,Sergeant-at-Arms Date,2017-12-03 -Winner(s),Dopey -Final Threshold,2 +Winner(s),Sneezy +Final Threshold,4 Contest Summary Number to be Elected,1 @@ -15,17 +15,17 @@ Number of Candidates,4 Total Number of Ballots,9 Number of Undervotes,0 -Rounds,Round 1 Votes,% of vote,transfer,Round 2 Votes,% of vote,transfer,Round 3 Votes,% of vote,transfer,Round 4 Votes,% of vote,transfer -Eliminated,Happy,,,Grumpy,,,Sneezy,,,,, -Elected,,,,,,,,,,Dopey,, -Sneezy,3,33.33%,0,3,33.33%,0,3,50.0%,-3,0,0.0%,0 -Dopey,3,33.33%,0,3,33.33%,0,3,50.0%,0,3,100.0%,0 -Grumpy,2,22.22%,1,3,33.33%,-3,0,0.0%,0,0,0.0%,0 -Happy,1,11.11%,-1,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Active Ballots,9,,,9,,,6,,,3,, -Current Round Threshold,5,,,5,,,4,,,2,, -Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0 -Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0 -Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,0 -Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0 -Inactive Ballots Total,0,,0,0,,3,3,,3,6,,0 +Rounds,Round 1 Votes,% of vote,transfer,Round 2 Votes,% of vote,transfer,Round 3 Votes,% of vote,transfer +Eliminated,Happy,,,Grumpy,,,,, +Elected,,,,,,,Sneezy,, +Sneezy,3,33.33%,0,3,33.33%,0,3,50.0%,0 +Dopey,3,33.33%,0,3,33.33%,0,3,50.0%,0 +Grumpy,2,22.22%,1,3,33.33%,-3,0,0.0%,0 +Happy,1,11.11%,-1,0,0.0%,0,0,0.0%,0 +Active Ballots,9,,,9,,,6,, +Current Round Threshold,5,,,5,,,4,, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,0,0,,3,3,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/tiebreak_previous_round_counts_then_random_test/tiebreak_previous_round_counts_then_random_test_expected_summary.json b/src/test/resources/network/brightspots/rcv/test_data/tiebreak_previous_round_counts_then_random_test/tiebreak_previous_round_counts_then_random_test_expected_summary.json index 4a39fd6..0b1751e 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/tiebreak_previous_round_counts_then_random_test/tiebreak_previous_round_counts_then_random_test_expected_summary.json +++ b/src/test/resources/network/brightspots/rcv/test_data/tiebreak_previous_round_counts_then_random_test/tiebreak_previous_round_counts_then_random_test_expected_summary.json @@ -61,31 +61,13 @@ "Sneezy" : "3" }, "tallyResults" : [ { - "eliminated" : "Sneezy", - "transfers" : { - "exhausted" : "3" - } - } ], - "threshold" : "4" - }, { - "inactiveBallots" : { - "exhaustedChoices" : "0", - "overvotes" : "0", - "repeatedRankings" : "0", - "skippedRankings" : "0" - }, - "round" : 4, - "tally" : { - "Dopey" : "3" - }, - "tallyResults" : [ { - "elected" : "Dopey", + "elected" : "Sneezy", "transfers" : { } } ], - "threshold" : "2" + "threshold" : "4" } ], "summary" : { - "finalThreshold" : "2", + "finalThreshold" : "4", "numCandidates" : 4, "numWinners" : 1, "totalNumBallots" : "9", diff --git a/src/test/resources/network/brightspots/rcv/test_data/tiebreak_seed_test/tiebreak_seed_test_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/tiebreak_seed_test/tiebreak_seed_test_expected_summary.csv index 0063996..1cbd4a9 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/tiebreak_seed_test/tiebreak_seed_test_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/tiebreak_seed_test/tiebreak_seed_test_expected_summary.csv @@ -6,8 +6,8 @@ Contest,Tiebreak test Jurisdiction,"Funkytown, USA" Office,Sergeant-at-Arms Date,2017-12-03 -Winner(s),Mookie Blaylock -Final Threshold,2 +Winner(s),George Gervin +Final Threshold,4 Contest Summary Number to be Elected,1 @@ -15,16 +15,16 @@ Number of Candidates,3 Total Number of Ballots,9 Number of Undervotes,0 -Rounds,Round 1 Votes,% of vote,transfer,Round 2 Votes,% of vote,transfer,Round 3 Votes,% of vote,transfer -Eliminated,Yinka Dare,,,George Gervin,,,,, -Elected,,,,,,,Mookie Blaylock,, -Yinka Dare,3,33.33%,-3,0,0.0%,0,0,0.0%,0 -George Gervin,3,33.33%,0,3,50.0%,-3,0,0.0%,0 -Mookie Blaylock,3,33.33%,0,3,50.0%,0,3,100.0%,0 -Active Ballots,9,,,6,,,3,, -Current Round Threshold,5,,,4,,,2,, -Inactive Ballots by Overvotes,0,,0,0,,0,0,,0 -Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0 -Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0 -Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0 -Inactive Ballots Total,0,,3,3,,3,6,,0 +Rounds,Round 1 Votes,% of vote,transfer,Round 2 Votes,% of vote,transfer +Eliminated,Yinka Dare,,,,, +Elected,,,,George Gervin,, +Yinka Dare,3,33.33%,-3,0,0.0%,0 +George Gervin,3,33.33%,0,3,50.0%,0 +Mookie Blaylock,3,33.33%,0,3,50.0%,0 +Active Ballots,9,,,6,, +Current Round Threshold,5,,,4,, +Inactive Ballots by Overvotes,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0 +Inactive Ballots Total,0,,3,3,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/tiebreak_seed_test/tiebreak_seed_test_expected_summary.json b/src/test/resources/network/brightspots/rcv/test_data/tiebreak_seed_test/tiebreak_seed_test_expected_summary.json index baf42cf..eacfb91 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/tiebreak_seed_test/tiebreak_seed_test_expected_summary.json +++ b/src/test/resources/network/brightspots/rcv/test_data/tiebreak_seed_test/tiebreak_seed_test_expected_summary.json @@ -40,31 +40,13 @@ "Mookie Blaylock" : "3" }, "tallyResults" : [ { - "eliminated" : "George Gervin", - "transfers" : { - "exhausted" : "3" - } - } ], - "threshold" : "4" - }, { - "inactiveBallots" : { - "exhaustedChoices" : "0", - "overvotes" : "0", - "repeatedRankings" : "0", - "skippedRankings" : "0" - }, - "round" : 3, - "tally" : { - "Mookie Blaylock" : "3" - }, - "tallyResults" : [ { - "elected" : "Mookie Blaylock", + "elected" : "George Gervin", "transfers" : { } } ], - "threshold" : "2" + "threshold" : "4" } ], "summary" : { - "finalThreshold" : "2", + "finalThreshold" : "4", "numCandidates" : 3, "numWinners" : 1, "totalNumBallots" : "9", diff --git a/src/test/resources/network/brightspots/rcv/test_data/tiebreak_use_permutation_in_config_test/tiebreak_use_permutation_in_config_test_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/tiebreak_use_permutation_in_config_test/tiebreak_use_permutation_in_config_test_expected_summary.csv index de8b753..64eb3e9 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/tiebreak_use_permutation_in_config_test/tiebreak_use_permutation_in_config_test_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/tiebreak_use_permutation_in_config_test/tiebreak_use_permutation_in_config_test_expected_summary.csv @@ -7,7 +7,7 @@ Jurisdiction,"Funkytown, USA" Office,Sergeant-at-Arms Date,2017-12-03 Winner(s),Mookie Blaylock -Final Threshold,3 +Final Threshold,5 Contest Summary Number to be Elected,1 @@ -15,17 +15,17 @@ Number of Candidates,4 Total Number of Ballots,10 Number of Undervotes,0 -Rounds,Round 1 Votes,% of vote,transfer,Round 2 Votes,% of vote,transfer,Round 3 Votes,% of vote,transfer,Round 4 Votes,% of vote,transfer -Eliminated,Sedale Threatt,,,George Gervin,,,Yinka Dare,,,,, -Elected,,,,,,,,,,Mookie Blaylock,, -Mookie Blaylock,4,40.0%,0,4,40.0%,0,4,50.0%,0,4,100.0%,0 -Yinka Dare,3,30.0%,0,3,30.0%,1,4,50.0%,-4,0,0.0%,0 -George Gervin,2,20.0%,1,3,30.0%,-3,0,0.0%,0,0,0.0%,0 -Sedale Threatt,1,10.0%,-1,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Active Ballots,10,,,10,,,8,,,4,, -Current Round Threshold,6,,,6,,,5,,,3,, -Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0 -Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0 -Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,0 -Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0 -Inactive Ballots Total,0,,0,0,,2,2,,4,6,,0 +Rounds,Round 1 Votes,% of vote,transfer,Round 2 Votes,% of vote,transfer,Round 3 Votes,% of vote,transfer +Eliminated,Sedale Threatt,,,George Gervin,,,,, +Elected,,,,,,,Mookie Blaylock,, +Mookie Blaylock,4,40.0%,0,4,40.0%,0,4,50.0%,0 +Yinka Dare,3,30.0%,0,3,30.0%,1,4,50.0%,0 +George Gervin,2,20.0%,1,3,30.0%,-3,0,0.0%,0 +Sedale Threatt,1,10.0%,-1,0,0.0%,0,0,0.0%,0 +Active Ballots,10,,,10,,,8,, +Current Round Threshold,6,,,6,,,5,, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,0,0,,2,2,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/tiebreak_use_permutation_in_config_test/tiebreak_use_permutation_in_config_test_expected_summary.json b/src/test/resources/network/brightspots/rcv/test_data/tiebreak_use_permutation_in_config_test/tiebreak_use_permutation_in_config_test_expected_summary.json index 3e2babe..072ca2c 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/tiebreak_use_permutation_in_config_test/tiebreak_use_permutation_in_config_test_expected_summary.json +++ b/src/test/resources/network/brightspots/rcv/test_data/tiebreak_use_permutation_in_config_test/tiebreak_use_permutation_in_config_test_expected_summary.json @@ -62,31 +62,13 @@ "Yinka Dare" : "4" }, "tallyResults" : [ { - "eliminated" : "Yinka Dare", - "transfers" : { - "exhausted" : "4" - } - } ], - "threshold" : "5" - }, { - "inactiveBallots" : { - "exhaustedChoices" : "0", - "overvotes" : "0", - "repeatedRankings" : "0", - "skippedRankings" : "0" - }, - "round" : 4, - "tally" : { - "Mookie Blaylock" : "4" - }, - "tallyResults" : [ { "elected" : "Mookie Blaylock", "transfers" : { } } ], - "threshold" : "3" + "threshold" : "5" } ], "summary" : { - "finalThreshold" : "3", + "finalThreshold" : "5", "numCandidates" : 4, "numWinners" : 1, "totalNumBallots" : "10", diff --git a/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_city_council_member/unisyn_xml_cdf_city_council_member_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_city_council_member/unisyn_xml_cdf_city_council_member_expected_summary.csv index c85b2c1..b8adcc6 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_city_council_member/unisyn_xml_cdf_city_council_member_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_city_council_member/unisyn_xml_cdf_city_council_member_expected_summary.csv @@ -6,8 +6,8 @@ Contest,For City C Council Member (1/3) Jurisdiction, Office, Date,2019-03-06 -Winner(s),Stephen Miller -Final Threshold,7 +Winner(s),Terry Williams +Final Threshold,11 Contest Summary Number to be Elected,1 @@ -15,22 +15,22 @@ Number of Candidates,9 Total Number of Ballots,35 Number of Undervotes,6 -Rounds,Round 1 Votes,% of vote,transfer,Round 2 Votes,% of vote,transfer,Round 3 Votes,% of vote,transfer,Round 4 Votes,% of vote,transfer,Round 5 Votes,% of vote,transfer,Round 6 Votes,% of vote,transfer,Round 7 Votes,% of vote,transfer,Round 8 Votes,% of vote,transfer,Round 9 Votes,% of vote,transfer -Eliminated,Undeclared Write-ins,,,Sylvia Vaugn,,,Nolan Ryder,,,Carrie Underwood,,,Hal Newman,,,Fred Wallace,,,Lonnie Alsup,,,Terry Williams,,,,, -Elected,,,,,,,,,,,,,,,,,,,,,,,,,Stephen Miller,, -Stephen Miller,5,17.24%,1,6,20.68%,0,6,20.68%,1,7,24.13%,1,8,27.58%,0,8,27.58%,2,10,37.03%,0,10,50.0%,2,12,100.0%,0 -Terry Williams,4,13.79%,0,4,13.79%,0,4,13.79%,1,5,17.24%,2,7,24.13%,3,10,34.48%,0,10,37.03%,0,10,50.0%,-10,0,0.0%,0 -Hal Newman,4,13.79%,0,4,13.79%,0,4,13.79%,0,4,13.79%,0,4,13.79%,-4,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Carrie Underwood,4,13.79%,0,4,13.79%,0,4,13.79%,0,4,13.79%,-4,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Lonnie Alsup,4,13.79%,0,4,13.79%,0,4,13.79%,0,4,13.79%,1,5,17.24%,1,6,20.68%,1,7,25.92%,-7,0,0.0%,0,0,0.0%,0 -Fred Wallace,3,10.34%,0,3,10.34%,1,4,13.79%,1,5,17.24%,0,5,17.24%,0,5,17.24%,-5,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Nolan Ryder,2,6.89%,0,2,6.89%,1,3,10.34%,-3,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Sylvia Vaugn,2,6.89%,0,2,6.89%,-2,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Undeclared Write-ins,1,3.44%,-1,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Active Ballots,29,,,29,,,29,,,29,,,29,,,29,,,27,,,20,,,12,, -Current Round Threshold,15,,,15,,,15,,,15,,,15,,,15,,,14,,,11,,,7,, -Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 -Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 -Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,0,0,,0,0,,2,2,,7,9,,8,17,,0 -Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 -Inactive Ballots Total,0,,0,0,,0,0,,0,0,,0,0,,0,0,,2,2,,7,9,,8,17,,0 +Rounds,Round 1 Votes,% of vote,transfer,Round 2 Votes,% of vote,transfer,Round 3 Votes,% of vote,transfer,Round 4 Votes,% of vote,transfer,Round 5 Votes,% of vote,transfer,Round 6 Votes,% of vote,transfer,Round 7 Votes,% of vote,transfer,Round 8 Votes,% of vote,transfer +Eliminated,Undeclared Write-ins,,,Sylvia Vaugn,,,Nolan Ryder,,,Carrie Underwood,,,Hal Newman,,,Fred Wallace,,,Lonnie Alsup,,,,, +Elected,,,,,,,,,,,,,,,,,,,,,,Terry Williams,, +Stephen Miller,5,17.24%,1,6,20.68%,0,6,20.68%,1,7,24.13%,1,8,27.58%,0,8,27.58%,2,10,37.03%,0,10,50.0%,0 +Terry Williams,4,13.79%,0,4,13.79%,0,4,13.79%,1,5,17.24%,2,7,24.13%,3,10,34.48%,0,10,37.03%,0,10,50.0%,0 +Hal Newman,4,13.79%,0,4,13.79%,0,4,13.79%,0,4,13.79%,0,4,13.79%,-4,0,0.0%,0,0,0.0%,0,0,0.0%,0 +Carrie Underwood,4,13.79%,0,4,13.79%,0,4,13.79%,0,4,13.79%,-4,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 +Lonnie Alsup,4,13.79%,0,4,13.79%,0,4,13.79%,0,4,13.79%,1,5,17.24%,1,6,20.68%,1,7,25.92%,-7,0,0.0%,0 +Fred Wallace,3,10.34%,0,3,10.34%,1,4,13.79%,1,5,17.24%,0,5,17.24%,0,5,17.24%,-5,0,0.0%,0,0,0.0%,0 +Nolan Ryder,2,6.89%,0,2,6.89%,1,3,10.34%,-3,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 +Sylvia Vaugn,2,6.89%,0,2,6.89%,-2,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 +Undeclared Write-ins,1,3.44%,-1,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 +Active Ballots,29,,,29,,,29,,,29,,,29,,,29,,,27,,,20,, +Current Round Threshold,15,,,15,,,15,,,15,,,15,,,15,,,14,,,11,, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,0,0,,0,0,,2,2,,7,9,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,0,0,,0,0,,0,0,,0,0,,0,0,,2,2,,7,9,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_city_council_member/unisyn_xml_cdf_city_council_member_expected_summary.json b/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_city_council_member/unisyn_xml_cdf_city_council_member_expected_summary.json index 993926b..ed9caa5 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_city_council_member/unisyn_xml_cdf_city_council_member_expected_summary.json +++ b/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_city_council_member/unisyn_xml_cdf_city_council_member_expected_summary.json @@ -189,32 +189,13 @@ "Terry Williams" : "10" }, "tallyResults" : [ { - "eliminated" : "Terry Williams", - "transfers" : { - "Stephen Miller" : "2", - "exhausted" : "8" - } - } ], - "threshold" : "11" - }, { - "inactiveBallots" : { - "exhaustedChoices" : "17", - "overvotes" : "0", - "repeatedRankings" : "0", - "skippedRankings" : "0" - }, - "round" : 9, - "tally" : { - "Stephen Miller" : "12" - }, - "tallyResults" : [ { - "elected" : "Stephen Miller", + "elected" : "Terry Williams", "transfers" : { } } ], - "threshold" : "7" + "threshold" : "11" } ], "summary" : { - "finalThreshold" : "7", + "finalThreshold" : "11", "numCandidates" : 9, "numWinners" : 1, "totalNumBallots" : "35", diff --git a/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_county_coroner/unisyn_xml_cdf_county_coroner_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_county_coroner/unisyn_xml_cdf_county_coroner_expected_summary.csv index 495c196..9b2a3ca 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_county_coroner/unisyn_xml_cdf_county_coroner_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_county_coroner/unisyn_xml_cdf_county_coroner_expected_summary.csv @@ -6,8 +6,8 @@ Contest,For County Coroner (1/2) Jurisdiction, Office, Date,2019-03-06 -Winner(s),Niels Larson -Final Threshold,5 +Winner(s),Willy Wonka +Final Threshold,10 Contest Summary Number to be Elected,1 @@ -15,22 +15,22 @@ Number of Candidates,9 Total Number of Ballots,35 Number of Undervotes,6 -Rounds,Round 1 Votes,% of vote,transfer,Round 2 Votes,% of vote,transfer,Round 3 Votes,% of vote,transfer,Round 4 Votes,% of vote,transfer,Round 5 Votes,% of vote,transfer,Round 6 Votes,% of vote,transfer,Round 7 Votes,% of vote,transfer,Round 8 Votes,% of vote,transfer,Round 9 Votes,% of vote,transfer -Eliminated,Undeclared Write-ins,,,Laura Brown,,,Andrea Doria,,,Kay Daniels,,,Walter Gerber,,,Emily Steffan,,,Jimmy Hendriks,,,Willy Wonka,,,,, -Elected,,,,,,,,,,,,,,,,,,,,,,,,,Niels Larson,, -Willy Wonka,5,17.24%,0,5,17.24%,1,6,20.68%,0,6,20.68%,0,6,20.68%,0,6,24.0%,3,9,37.5%,0,9,50.0%,-9,0,0.0%,0 -Niels Larson,5,17.24%,0,5,17.24%,0,5,17.24%,1,6,20.68%,2,8,27.58%,0,8,32.0%,0,8,33.33%,1,9,50.0%,0,9,100.0%,0 -Emily Steffan,4,13.79%,0,4,13.79%,0,4,13.79%,0,4,13.79%,0,4,13.79%,0,4,16.0%,-4,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Laura Brown,3,10.34%,0,3,10.34%,-3,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Kay Daniels,3,10.34%,0,3,10.34%,0,3,10.34%,0,3,10.34%,-3,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Andrea Doria,3,10.34%,0,3,10.34%,0,3,10.34%,-3,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Jimmy Hendriks,3,10.34%,0,3,10.34%,1,4,13.79%,2,6,20.68%,1,7,24.13%,0,7,28.0%,0,7,29.16%,-7,0,0.0%,0,0,0.0%,0 -Walter Gerber,3,10.34%,0,3,10.34%,1,4,13.79%,0,4,13.79%,0,4,13.79%,-4,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Undeclared Write-ins,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Active Ballots,29,,,29,,,29,,,29,,,29,,,25,,,24,,,18,,,9,, -Current Round Threshold,15,,,15,,,15,,,15,,,15,,,13,,,13,,,10,,,5,, -Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 -Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 -Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,0,0,,4,4,,1,5,,6,11,,9,20,,0 -Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 -Inactive Ballots Total,0,,0,0,,0,0,,0,0,,0,0,,4,4,,1,5,,6,11,,9,20,,0 +Rounds,Round 1 Votes,% of vote,transfer,Round 2 Votes,% of vote,transfer,Round 3 Votes,% of vote,transfer,Round 4 Votes,% of vote,transfer,Round 5 Votes,% of vote,transfer,Round 6 Votes,% of vote,transfer,Round 7 Votes,% of vote,transfer,Round 8 Votes,% of vote,transfer +Eliminated,Undeclared Write-ins,,,Laura Brown,,,Andrea Doria,,,Kay Daniels,,,Walter Gerber,,,Emily Steffan,,,Jimmy Hendriks,,,,, +Elected,,,,,,,,,,,,,,,,,,,,,,Willy Wonka,, +Willy Wonka,5,17.24%,0,5,17.24%,1,6,20.68%,0,6,20.68%,0,6,20.68%,0,6,24.0%,3,9,37.5%,0,9,50.0%,0 +Niels Larson,5,17.24%,0,5,17.24%,0,5,17.24%,1,6,20.68%,2,8,27.58%,0,8,32.0%,0,8,33.33%,1,9,50.0%,0 +Emily Steffan,4,13.79%,0,4,13.79%,0,4,13.79%,0,4,13.79%,0,4,13.79%,0,4,16.0%,-4,0,0.0%,0,0,0.0%,0 +Laura Brown,3,10.34%,0,3,10.34%,-3,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 +Kay Daniels,3,10.34%,0,3,10.34%,0,3,10.34%,0,3,10.34%,-3,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 +Andrea Doria,3,10.34%,0,3,10.34%,0,3,10.34%,-3,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 +Jimmy Hendriks,3,10.34%,0,3,10.34%,1,4,13.79%,2,6,20.68%,1,7,24.13%,0,7,28.0%,0,7,29.16%,-7,0,0.0%,0 +Walter Gerber,3,10.34%,0,3,10.34%,1,4,13.79%,0,4,13.79%,0,4,13.79%,-4,0,0.0%,0,0,0.0%,0,0,0.0%,0 +Undeclared Write-ins,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 +Active Ballots,29,,,29,,,29,,,29,,,29,,,25,,,24,,,18,, +Current Round Threshold,15,,,15,,,15,,,15,,,15,,,13,,,13,,,10,, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,0,0,,4,4,,1,5,,6,11,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,0,0,,0,0,,0,0,,0,0,,4,4,,1,5,,6,11,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_county_coroner/unisyn_xml_cdf_county_coroner_expected_summary.json b/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_county_coroner/unisyn_xml_cdf_county_coroner_expected_summary.json index 8546c2a..b2f7810 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_county_coroner/unisyn_xml_cdf_county_coroner_expected_summary.json +++ b/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_county_coroner/unisyn_xml_cdf_county_coroner_expected_summary.json @@ -185,31 +185,13 @@ "Willy Wonka" : "9" }, "tallyResults" : [ { - "eliminated" : "Willy Wonka", - "transfers" : { - "exhausted" : "9" - } - } ], - "threshold" : "10" - }, { - "inactiveBallots" : { - "exhaustedChoices" : "20", - "overvotes" : "0", - "repeatedRankings" : "0", - "skippedRankings" : "0" - }, - "round" : 9, - "tally" : { - "Niels Larson" : "9" - }, - "tallyResults" : [ { - "elected" : "Niels Larson", + "elected" : "Willy Wonka", "transfers" : { } } ], - "threshold" : "5" + "threshold" : "10" } ], "summary" : { - "finalThreshold" : "5", + "finalThreshold" : "10", "numCandidates" : 9, "numWinners" : 1, "totalNumBallots" : "35", diff --git a/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_county_sheriff/unisyn_xml_cdf_county_sheriff_expected_summary.csv b/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_county_sheriff/unisyn_xml_cdf_county_sheriff_expected_summary.csv index a05d552..31b7d4a 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_county_sheriff/unisyn_xml_cdf_county_sheriff_expected_summary.csv +++ b/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_county_sheriff/unisyn_xml_cdf_county_sheriff_expected_summary.csv @@ -6,8 +6,8 @@ Contest,For County Sheriff (1/3) Jurisdiction, Office, Date,2019-03-06 -Winner(s),Terry Baker -Final Threshold,9 +Winner(s),Warren Norell +Final Threshold,13 Contest Summary Number to be Elected,1 @@ -15,21 +15,21 @@ Number of Candidates,8 Total Number of Ballots,35 Number of Undervotes,6 -Rounds,Round 1 Votes,% of vote,transfer,Round 2 Votes,% of vote,transfer,Round 3 Votes,% of vote,transfer,Round 4 Votes,% of vote,transfer,Round 5 Votes,% of vote,transfer,Round 6 Votes,% of vote,transfer,Round 7 Votes,% of vote,transfer,Round 8 Votes,% of vote,transfer -Eliminated,Undeclared Write-ins,,,Beth Small,,,Thomas Soto,,,Sandra Williams,,,John Wayne Jr.,,,Tony Seiler,,,Warren Norell,,,,, -Elected,,,,,,,,,,,,,,,,,,,,,,Terry Baker,, -Terry Baker,5,17.24%,0,5,17.24%,2,7,24.13%,0,7,24.13%,0,7,24.13%,3,10,34.48%,2,12,50.0%,5,17,100.0%,0 -John Wayne Jr.,5,17.24%,1,6,20.68%,0,6,20.68%,1,7,24.13%,0,7,24.13%,-7,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Tony Seiler,5,17.24%,1,6,20.68%,0,6,20.68%,0,6,20.68%,1,7,24.13%,2,9,31.03%,-9,0,0.0%,0,0,0.0%,0 -Warren Norell,4,13.79%,0,4,13.79%,0,4,13.79%,2,6,20.68%,2,8,27.58%,2,10,34.48%,2,12,50.0%,-12,0,0.0%,0 -Thomas Soto,3,10.34%,0,3,10.34%,0,3,10.34%,-3,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Sandra Williams,3,10.34%,0,3,10.34%,0,3,10.34%,0,3,10.34%,-3,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Beth Small,2,6.89%,0,2,6.89%,-2,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Undeclared Write-ins,2,6.89%,-2,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 -Active Ballots,29,,,29,,,29,,,29,,,29,,,29,,,24,,,17,, -Current Round Threshold,15,,,15,,,15,,,15,,,15,,,15,,,13,,,9,, -Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 -Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 -Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,0,0,,0,0,,5,5,,7,12,,0 -Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 -Inactive Ballots Total,0,,0,0,,0,0,,0,0,,0,0,,0,0,,5,5,,7,12,,0 +Rounds,Round 1 Votes,% of vote,transfer,Round 2 Votes,% of vote,transfer,Round 3 Votes,% of vote,transfer,Round 4 Votes,% of vote,transfer,Round 5 Votes,% of vote,transfer,Round 6 Votes,% of vote,transfer,Round 7 Votes,% of vote,transfer +Eliminated,Undeclared Write-ins,,,Beth Small,,,Thomas Soto,,,Sandra Williams,,,John Wayne Jr.,,,Tony Seiler,,,,, +Elected,,,,,,,,,,,,,,,,,,,Warren Norell,, +Terry Baker,5,17.24%,0,5,17.24%,2,7,24.13%,0,7,24.13%,0,7,24.13%,3,10,34.48%,2,12,50.0%,0 +John Wayne Jr.,5,17.24%,1,6,20.68%,0,6,20.68%,1,7,24.13%,0,7,24.13%,-7,0,0.0%,0,0,0.0%,0 +Tony Seiler,5,17.24%,1,6,20.68%,0,6,20.68%,0,6,20.68%,1,7,24.13%,2,9,31.03%,-9,0,0.0%,0 +Warren Norell,4,13.79%,0,4,13.79%,0,4,13.79%,2,6,20.68%,2,8,27.58%,2,10,34.48%,2,12,50.0%,0 +Thomas Soto,3,10.34%,0,3,10.34%,0,3,10.34%,-3,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 +Sandra Williams,3,10.34%,0,3,10.34%,0,3,10.34%,0,3,10.34%,-3,0,0.0%,0,0,0.0%,0,0,0.0%,0 +Beth Small,2,6.89%,0,2,6.89%,-2,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 +Undeclared Write-ins,2,6.89%,-2,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0,0,0.0%,0 +Active Ballots,29,,,29,,,29,,,29,,,29,,,29,,,24,, +Current Round Threshold,15,,,15,,,15,,,15,,,15,,,15,,,13,, +Inactive Ballots by Overvotes,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Skipped Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots by Exhausted Choices,0,,0,0,,0,0,,0,0,,0,0,,0,0,,5,5,,0 +Inactive Ballots by Repeated Rankings,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0,0,,0 +Inactive Ballots Total,0,,0,0,,0,0,,0,0,,0,0,,0,0,,5,5,,0 diff --git a/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_county_sheriff/unisyn_xml_cdf_county_sheriff_expected_summary.json b/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_county_sheriff/unisyn_xml_cdf_county_sheriff_expected_summary.json index ac8d06a..565f50d 100644 --- a/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_county_sheriff/unisyn_xml_cdf_county_sheriff_expected_summary.json +++ b/src/test/resources/network/brightspots/rcv/test_data/unisyn_xml_cdf_county_sheriff/unisyn_xml_cdf_county_sheriff_expected_summary.json @@ -162,32 +162,13 @@ "Warren Norell" : "12" }, "tallyResults" : [ { - "eliminated" : "Warren Norell", - "transfers" : { - "Terry Baker" : "5", - "exhausted" : "7" - } - } ], - "threshold" : "13" - }, { - "inactiveBallots" : { - "exhaustedChoices" : "12", - "overvotes" : "0", - "repeatedRankings" : "0", - "skippedRankings" : "0" - }, - "round" : 8, - "tally" : { - "Terry Baker" : "17" - }, - "tallyResults" : [ { - "elected" : "Terry Baker", + "elected" : "Warren Norell", "transfers" : { } } ], - "threshold" : "9" + "threshold" : "13" } ], "summary" : { - "finalThreshold" : "9", + "finalThreshold" : "13", "numCandidates" : 8, "numWinners" : 1, "totalNumBallots" : "35",
https://github.com/BrightSpots/rcv.gitdiff --git a/src/main/java/network/brightspots/rcv/Tabulator.java b/src/main/java/network/brightspots/rcv/Tabulator.java
gitbug-java_data_ezylang-EvalEx.json_1
diff --git a/src/main/java/com/ezylang/evalex/parser/Tokenizer.java b/src/main/java/com/ezylang/evalex/parser/Tokenizer.java index abb2085..08d2979 100644 --- a/src/main/java/com/ezylang/evalex/parser/Tokenizer.java +++ b/src/main/java/com/ezylang/evalex/parser/Tokenizer.java @@ -351,33 +351,54 @@ public class Tokenizer { } private Token parseNumberLiteral() throws ParseException { - int tokenStartIndex = currentColumnIndex; - StringBuilder tokenValue = new StringBuilder(); int nextChar = peekNextChar(); if (currentChar == '0' && (nextChar == 'x' || nextChar == 'X')) { - // hexadecimal number, consume "0x" + return parseHexNumberLiteral(); + } else { + return parseDecimalNumberLiteral(); + } + } + + private Token parseDecimalNumberLiteral() throws ParseException { + int tokenStartIndex = currentColumnIndex; + StringBuilder tokenValue = new StringBuilder(); + + int lastChar = -1; + boolean scientificNotation = false; + while (currentChar != -1 && isAtNumberChar()) { + if (currentChar == 'e' || currentChar == 'E') { + scientificNotation = true; + } tokenValue.append((char) currentChar); + lastChar = currentChar; consumeChar(); + } + // illegal scientific format literal + if (scientificNotation + && (lastChar == 'e' + || lastChar == 'E' + || lastChar == '+' + || lastChar == '-' + || lastChar == '.')) { + throw new ParseException( + new Token(tokenStartIndex, tokenValue.toString(), TokenType.NUMBER_LITERAL), + "Illegal scientific format"); + } + return new Token(tokenStartIndex, tokenValue.toString(), TokenType.NUMBER_LITERAL); + } + + private Token parseHexNumberLiteral() { + int tokenStartIndex = currentColumnIndex; + StringBuilder tokenValue = new StringBuilder(); + + // hexadecimal number, consume "0x" + tokenValue.append((char) currentChar); + consumeChar(); + tokenValue.append((char) currentChar); + consumeChar(); + while (currentChar != -1 && isAtHexChar()) { tokenValue.append((char) currentChar); consumeChar(); - while (currentChar != -1 && isAtHexChar()) { - tokenValue.append((char) currentChar); - consumeChar(); - } - } else { - // decimal number - int lastChar = -1; - while (currentChar != -1 && isAtNumberChar()) { - tokenValue.append((char) currentChar); - lastChar = currentChar; - consumeChar(); - } - // illegal scientific format literal - if (lastChar == 'e' || lastChar == 'E' || lastChar == '+' || lastChar == '-') { - throw new ParseException( - new Token(tokenStartIndex, tokenValue.toString(), TokenType.NUMBER_LITERAL), - "Illegal scientific format"); - } } return new Token(tokenStartIndex, tokenValue.toString(), TokenType.NUMBER_LITERAL); } @@ -485,7 +506,7 @@ public class Tokenizer { private boolean isAtNumberChar() { int previousChar = peekPreviousChar(); - if (previousChar == 'e' || previousChar == 'E') { + if ((previousChar == 'e' || previousChar == 'E') && currentChar != '.') { return Character.isDigit(currentChar) || currentChar == '+' || currentChar == '-'; } diff --git a/src/test/java/com/ezylang/evalex/parser/ShuntingYardExceptionsTest.java b/src/test/java/com/ezylang/evalex/parser/ShuntingYardExceptionsTest.java index 8f23723..9a261b1 100644 --- a/src/test/java/com/ezylang/evalex/parser/ShuntingYardExceptionsTest.java +++ b/src/test/java/com/ezylang/evalex/parser/ShuntingYardExceptionsTest.java @@ -151,7 +151,9 @@ class ShuntingYardExceptionsTest extends BaseParserTest { "Hello 1 + 1", "Hello World", "Hello 1", - "1 2" + "1 2", + "e.1", + "E.1" }) void testTooManyOperands(String expressionString) { Expression expression = new Expression(expressionString); diff --git a/src/test/java/com/ezylang/evalex/parser/TokenizerNumberLiteralTest.java b/src/test/java/com/ezylang/evalex/parser/TokenizerNumberLiteralTest.java index 2c41fcb..a27c229 100644 --- a/src/test/java/com/ezylang/evalex/parser/TokenizerNumberLiteralTest.java +++ b/src/test/java/com/ezylang/evalex/parser/TokenizerNumberLiteralTest.java @@ -83,7 +83,7 @@ class TokenizerNumberLiteralTest extends BaseParserTest { } @ParameterizedTest - @ValueSource(strings = {"2e", "2E", "2e+", "2E+", "2e-", "2E-", "2e."}) + @ValueSource(strings = {"2e", "2E", "2e+", "2E+", "2e-", "2E-", "2e.", "2E.", "2ex", "2Ex"}) void testScientificLiteralsParseException(String expression) { assertThatThrownBy(() -> new Tokenizer(expression, configuration).parse()) .isInstanceOf(ParseException.class)
https://github.com/ezylang/EvalEx.gitdiff --git a/src/main/java/com/ezylang/evalex/parser/Tokenizer.java b/src/main/java/com/ezylang/evalex/parser/Tokenizer.java
gitbug-java_data_stellar-java-stellar-sdk.json_1
diff --git a/src/main/java/org/stellar/sdk/KeyPair.java b/src/main/java/org/stellar/sdk/KeyPair.java index ec7e490..97fdcc0 100644 --- a/src/main/java/org/stellar/sdk/KeyPair.java +++ b/src/main/java/org/stellar/sdk/KeyPair.java @@ -308,7 +308,7 @@ public class KeyPair { } KeyPair other = (KeyPair) object; - return this.mPrivateKey.equals(other.mPrivateKey) && + return Objects.equal(this.mPrivateKey, other.mPrivateKey) && this.mPublicKey.equals(other.mPublicKey); } diff --git a/src/test/java/org/stellar/sdk/KeyPairTest.java b/src/test/java/org/stellar/sdk/KeyPairTest.java index 680484c..eb2b655 100644 --- a/src/test/java/org/stellar/sdk/KeyPairTest.java +++ b/src/test/java/org/stellar/sdk/KeyPairTest.java @@ -120,4 +120,25 @@ public class KeyPairTest { // the hint could only be derived off of 3 bytes from payload Assert.assertArrayEquals(sig.getHint().getSignatureHint(), new byte[]{(byte)(255), 64, 7, 55}); } + + @Test + public void testPublicEqual() { + KeyPair keypair = KeyPair.fromAccountId("GDEAOZWTVHQZGGJY6KG4NAGJQ6DXATXAJO3AMW7C4IXLKMPWWB4FDNFZ"); + KeyPair keypairCopy = KeyPair.fromAccountId("GDEAOZWTVHQZGGJY6KG4NAGJQ6DXATXAJO3AMW7C4IXLKMPWWB4FDNFZ"); + Assert.assertEquals(keypairCopy, keypair); + } + + @Test + public void testPublicPrivateNotEquals() { + KeyPair keypair = KeyPair.random(); + KeyPair keypairPublicCopy = KeyPair.fromAccountId(keypair.getAccountId()); + Assert.assertNotEquals(keypairPublicCopy, keypair); + } + + @Test + public void testPrivateEquals() { + KeyPair keyPair = KeyPair.random(); + KeyPair keypairCopy = KeyPair.fromSecretSeed(keyPair.getSecretSeed()); + Assert.assertEquals(keyPair, keypairCopy); + } }
https://github.com/stellar/java-stellar-sdk.gitdiff --git a/src/main/java/org/stellar/sdk/KeyPair.java b/src/main/java/org/stellar/sdk/KeyPair.java
gitbug-java_data_stellar-java-stellar-sdk.json_2
diff --git a/src/main/java/org/stellar/sdk/Transaction.java b/src/main/java/org/stellar/sdk/Transaction.java index 316c88c..56beee7 100644 --- a/src/main/java/org/stellar/sdk/Transaction.java +++ b/src/main/java/org/stellar/sdk/Transaction.java @@ -402,7 +402,7 @@ public class Transaction extends AbstractTransaction { Operation op = mOperations[0]; return op instanceof InvokeHostFunctionOperation - || op instanceof BumpSequenceOperation + || op instanceof BumpFootprintExpirationOperation || op instanceof RestoreFootprintOperation; } } diff --git a/src/test/java/org/stellar/sdk/TransactionTest.java b/src/test/java/org/stellar/sdk/TransactionTest.java index a121ea8..2724d56 100644 --- a/src/test/java/org/stellar/sdk/TransactionTest.java +++ b/src/test/java/org/stellar/sdk/TransactionTest.java @@ -2,6 +2,7 @@ package org.stellar.sdk; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -12,8 +13,34 @@ import java.math.BigInteger; import java.security.SecureRandom; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; +import java.util.List; import org.junit.Test; -import org.stellar.sdk.xdr.*; +import org.stellar.sdk.scval.Scv; +import org.stellar.sdk.xdr.ContractDataDurability; +import org.stellar.sdk.xdr.ContractEntryBodyType; +import org.stellar.sdk.xdr.ContractExecutable; +import org.stellar.sdk.xdr.ContractExecutableType; +import org.stellar.sdk.xdr.ContractIDPreimage; +import org.stellar.sdk.xdr.ContractIDPreimageType; +import org.stellar.sdk.xdr.CreateContractArgs; +import org.stellar.sdk.xdr.DecoratedSignature; +import org.stellar.sdk.xdr.EnvelopeType; +import org.stellar.sdk.xdr.ExtensionPoint; +import org.stellar.sdk.xdr.HostFunction; +import org.stellar.sdk.xdr.HostFunctionType; +import org.stellar.sdk.xdr.Int64; +import org.stellar.sdk.xdr.LedgerEntryType; +import org.stellar.sdk.xdr.LedgerFootprint; +import org.stellar.sdk.xdr.LedgerKey; +import org.stellar.sdk.xdr.SCVal; +import org.stellar.sdk.xdr.SignerKey; +import org.stellar.sdk.xdr.SorobanResources; +import org.stellar.sdk.xdr.SorobanTransactionData; +import org.stellar.sdk.xdr.Uint256; +import org.stellar.sdk.xdr.Uint32; +import org.stellar.sdk.xdr.XdrDataInputStream; +import org.stellar.sdk.xdr.XdrUnsignedInteger; public class TransactionTest { @@ -58,7 +85,7 @@ public class TransactionTest { (Transaction) Transaction.fromEnvelopeXdr( AccountConverter.enableMuxed(), transaction.toEnvelopeXdrBase64(), Network.PUBLIC); - assertTrue(parsed.equals(transaction)); + assertEquals(parsed, transaction); assertEquals(EnvelopeType.ENVELOPE_TYPE_TX_V0, parsed.toEnvelopeXdr().getDiscriminant()); assertEquals(transaction.toEnvelopeXdrBase64(), parsed.toEnvelopeXdrBase64()); @@ -260,4 +287,164 @@ public class TransactionTest { "AAAAAgAAAABexSIg06FtXzmFBQQtHZsrnyWxUzmthkBEhs/ktoeVYgAAAGQAClWjAAAAAQAAAAAAAAAAAAAAAQAAAAAAAAAYAAAAAQAAAAAAAAAAAAAAAH8wYjTJienWf2nf2TEZi2APPWzmtkwiQHAftisIgyuHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAEAAAAAAAAAAQAAAAAAAAAAfzBiNMmJ6dZ/ad/ZMRmLYA89bOa2TCJAcB+2KwiDK4cAAAAAAACHBwAAArsAAAAAAAAA2AAAAAAAAABkAAAAAA=="; assertEquals(expectedXdr, transaction.toEnvelopeXdrBase64()); } + + @Test + public void testIsSorobanTransactionInvokeHostFunctionOperation() { + KeyPair source = + KeyPair.fromSecretSeed("SCH27VUZZ6UAKB67BDNF6FA42YMBMQCBKXWGMFD5TZ6S5ZZCZFLRXKHS"); + + Account account = new Account(source.getAccountId(), 2908908335136768L); + + String contractId = "CDYUOBUVMZPWIU4GB4XNBAYL6NIHIMYLZFNEXOCDIO33MBJMNPSFBYKU"; + String functionName = "hello"; + List<SCVal> params = Collections.singletonList(Scv.toSymbol("Soroban")); + InvokeHostFunctionOperation operation = + InvokeHostFunctionOperation.invokeContractFunctionOperationBuilder( + contractId, functionName, params) + .build(); + + Transaction transaction = + new Transaction( + AccountConverter.enableMuxed(), + account.getAccountId(), + Transaction.MIN_BASE_FEE, + account.getIncrementedSequenceNumber(), + new org.stellar.sdk.Operation[] {operation}, + null, + new TransactionPreconditions( + null, null, BigInteger.ZERO, 0, new ArrayList<SignerKey>(), null), + null, + Network.TESTNET); + assertTrue(transaction.isSorobanTransaction()); + } + + @Test + public void testIsSorobanTransactionBumpFootprintExpirationOperation() { + KeyPair source = + KeyPair.fromSecretSeed("SCH27VUZZ6UAKB67BDNF6FA42YMBMQCBKXWGMFD5TZ6S5ZZCZFLRXKHS"); + + Account account = new Account(source.getAccountId(), 2908908335136768L); + String contractId = "CDYUOBUVMZPWIU4GB4XNBAYL6NIHIMYLZFNEXOCDIO33MBJMNPSFBYKU"; + SorobanTransactionData sorobanData = + new SorobanDataBuilder() + .setReadOnly( + Collections.singletonList( + new LedgerKey.Builder() + .discriminant(LedgerEntryType.CONTRACT_DATA) + .contractData( + new LedgerKey.LedgerKeyContractData.Builder() + .contract(new Address(contractId).toSCAddress()) + .key(Scv.toLedgerKeyContractInstance()) + .durability(ContractDataDurability.PERSISTENT) + .bodyType(ContractEntryBodyType.DATA_ENTRY) + .build()) + .build())) + .build(); + BumpFootprintExpirationOperation operation = + BumpFootprintExpirationOperation.builder().ledgersToExpire(4096L).build(); + Transaction transaction = + new Transaction( + AccountConverter.enableMuxed(), + account.getAccountId(), + Transaction.MIN_BASE_FEE, + account.getIncrementedSequenceNumber(), + new org.stellar.sdk.Operation[] {operation}, + null, + new TransactionPreconditions( + null, null, BigInteger.ZERO, 0, new ArrayList<SignerKey>(), null), + sorobanData, + Network.TESTNET); + assertTrue(transaction.isSorobanTransaction()); + } + + @Test + public void testIsSorobanTransactionRestoreFootprintOperation() { + KeyPair source = + KeyPair.fromSecretSeed("SCH27VUZZ6UAKB67BDNF6FA42YMBMQCBKXWGMFD5TZ6S5ZZCZFLRXKHS"); + + Account account = new Account(source.getAccountId(), 2908908335136768L); + String contractId = "CDYUOBUVMZPWIU4GB4XNBAYL6NIHIMYLZFNEXOCDIO33MBJMNPSFBYKU"; + SorobanTransactionData sorobanData = + new SorobanDataBuilder() + .setReadOnly( + Collections.singletonList( + new LedgerKey.Builder() + .discriminant(LedgerEntryType.CONTRACT_DATA) + .contractData( + new LedgerKey.LedgerKeyContractData.Builder() + .contract(new Address(contractId).toSCAddress()) + .key(Scv.toLedgerKeyContractInstance()) + .durability(ContractDataDurability.PERSISTENT) + .bodyType(ContractEntryBodyType.DATA_ENTRY) + .build()) + .build())) + .build(); + RestoreFootprintOperation operation = RestoreFootprintOperation.builder().build(); + Transaction transaction = + new Transaction( + AccountConverter.enableMuxed(), + account.getAccountId(), + Transaction.MIN_BASE_FEE, + account.getIncrementedSequenceNumber(), + new org.stellar.sdk.Operation[] {operation}, + null, + new TransactionPreconditions( + null, null, BigInteger.ZERO, 0, new ArrayList<SignerKey>(), null), + sorobanData, + Network.TESTNET); + assertTrue(transaction.isSorobanTransaction()); + } + + @Test + public void testIsSorobanTransactionMultiOperations() { + KeyPair source = + KeyPair.fromSecretSeed("SCH27VUZZ6UAKB67BDNF6FA42YMBMQCBKXWGMFD5TZ6S5ZZCZFLRXKHS"); + + Account account = new Account(source.getAccountId(), 2908908335136768L); + + String contractId = "CDYUOBUVMZPWIU4GB4XNBAYL6NIHIMYLZFNEXOCDIO33MBJMNPSFBYKU"; + String functionName = "hello"; + List<SCVal> params = Collections.singletonList(Scv.toSymbol("Soroban")); + InvokeHostFunctionOperation operation = + InvokeHostFunctionOperation.invokeContractFunctionOperationBuilder( + contractId, functionName, params) + .build(); + + Transaction transaction = + new Transaction( + AccountConverter.enableMuxed(), + account.getAccountId(), + Transaction.MIN_BASE_FEE, + account.getIncrementedSequenceNumber(), + new org.stellar.sdk.Operation[] {operation, operation}, + null, + new TransactionPreconditions( + null, null, BigInteger.ZERO, 0, new ArrayList<SignerKey>(), null), + null, + Network.TESTNET); + assertFalse(transaction.isSorobanTransaction()); + } + + @Test + public void testIsSorobanTransactionBumpSequenceOperation() { + KeyPair source = + KeyPair.fromSecretSeed("SCH27VUZZ6UAKB67BDNF6FA42YMBMQCBKXWGMFD5TZ6S5ZZCZFLRXKHS"); + + Account account = new Account(source.getAccountId(), 2908908335136768L); + BumpSequenceOperation operation = new BumpSequenceOperation.Builder(0L).build(); + + Transaction transaction = + new Transaction( + AccountConverter.enableMuxed(), + account.getAccountId(), + Transaction.MIN_BASE_FEE, + account.getIncrementedSequenceNumber(), + new org.stellar.sdk.Operation[] {operation}, + null, + new TransactionPreconditions( + null, null, BigInteger.ZERO, 0, new ArrayList<SignerKey>(), null), + null, + Network.TESTNET); + assertFalse(transaction.isSorobanTransaction()); + } }
https://github.com/stellar/java-stellar-sdk.gitdiff --git a/src/main/java/org/stellar/sdk/Transaction.java b/src/main/java/org/stellar/sdk/Transaction.java
gitbug-java_data_stellar-java-stellar-sdk.json_3
diff --git a/src/main/java/org/stellar/sdk/SorobanServer.java b/src/main/java/org/stellar/sdk/SorobanServer.java index 410721b..ff7f29a 100644 --- a/src/main/java/org/stellar/sdk/SorobanServer.java +++ b/src/main/java/org/stellar/sdk/SorobanServer.java @@ -354,7 +354,11 @@ public class SorobanServer implements Closeable { * must be one of {@link InvokeHostFunctionOperation}, {@link * BumpFootprintExpirationOperation}, or {@link RestoreFootprintOperation}. Any provided * footprint will be ignored. You can use {@link Transaction#isSorobanTransaction()} to check - * if a transaction is a Soroban transaction. + * if a transaction is a Soroban transaction. Any provided footprint will be overwritten. + * However, if your operation has existing auth entries, they will be preferred over ALL auth + * entries from the simulation. In other words, if you include auth entries, you don't care + * about the auth returned from the simulation. Other fields (footprint, etc.) will be filled + * as normal. * @return Returns a copy of the {@link Transaction}, with the expected authorizations (in the * case of invocation) and ledger footprint added. The transaction fee will also automatically * be padded with the contract's minimum resource fees discovered from the simulation. @@ -422,24 +426,30 @@ public class SorobanServer implements Closeable { Operation operation = transaction.getOperations()[0]; if (operation instanceof InvokeHostFunctionOperation) { - Collection<SorobanAuthorizationEntry> originalEntries = + // If the operation is an InvokeHostFunctionOperation, we need to update the auth entries if + // existing entries are empty and the simulation result contains auth entries. + Collection<SorobanAuthorizationEntry> existingEntries = ((InvokeHostFunctionOperation) operation).getAuth(); - List<SorobanAuthorizationEntry> newEntries = new ArrayList<>(originalEntries); - if (simulateHostFunctionResult.getAuth() != null) { + if (existingEntries.isEmpty() + && simulateHostFunctionResult.getAuth() != null + && !simulateHostFunctionResult.getAuth().isEmpty()) { + List<SorobanAuthorizationEntry> authorizationEntries = + new ArrayList<>(simulateHostFunctionResult.getAuth().size()); for (String auth : simulateHostFunctionResult.getAuth()) { try { - newEntries.add(SorobanAuthorizationEntry.fromXdrBase64(auth)); + authorizationEntries.add(SorobanAuthorizationEntry.fromXdrBase64(auth)); } catch (IOException e) { throw new IllegalArgumentException("Invalid auth: " + auth, e); } } + + operation = + InvokeHostFunctionOperation.builder() + .hostFunction(((InvokeHostFunctionOperation) operation).getHostFunction()) + .sourceAccount(operation.getSourceAccount()) + .auth(authorizationEntries) + .build(); } - operation = - InvokeHostFunctionOperation.builder() - .hostFunction(((InvokeHostFunctionOperation) operation).getHostFunction()) - .sourceAccount(operation.getSourceAccount()) - .auth(newEntries) - .build(); } SorobanTransactionData sorobanData; diff --git a/src/test/java/org/stellar/sdk/SorobanServerTest.java b/src/test/java/org/stellar/sdk/SorobanServerTest.java index 57bba78..c8671d7 100644 --- a/src/test/java/org/stellar/sdk/SorobanServerTest.java +++ b/src/test/java/org/stellar/sdk/SorobanServerTest.java @@ -1,5 +1,6 @@ package org.stellar.sdk; +import static com.google.common.collect.ImmutableList.of; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -15,7 +16,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.Optional; import okhttp3.HttpUrl; import okhttp3.mockwebserver.Dispatcher; @@ -104,8 +104,7 @@ public class SorobanServerTest { throws InterruptedException { GetLedgerEntriesRequest expectedRequest = new GetLedgerEntriesRequest( - Collections.singletonList( - "AAAAAAAAAADBPp7TMinJylnn+6dQXJACNc15LF+aJ2Py1BaR4P10JA==")); + of("AAAAAAAAAADBPp7TMinJylnn+6dQXJACNc15LF+aJ2Py1BaR4P10JA==")); SorobanRpcRequest<GetLedgerEntriesRequest> sorobanRpcRequest = gson.fromJson( recordedRequest.getBody().readUtf8(), @@ -256,8 +255,7 @@ public class SorobanServerTest { .build(); GetLedgerEntriesRequest expectedRequest = - new GetLedgerEntriesRequest( - Collections.singletonList(ledgerKeyToXdrBase64(ledgerKey))); + new GetLedgerEntriesRequest(of(ledgerKeyToXdrBase64(ledgerKey))); SorobanRpcRequest<GetLedgerEntriesRequest> sorobanRpcRequest = gson.fromJson( recordedRequest.getBody().readUtf8(), @@ -326,8 +324,7 @@ public class SorobanServerTest { .build(); GetLedgerEntriesRequest expectedRequest = - new GetLedgerEntriesRequest( - Collections.singletonList(ledgerKeyToXdrBase64(ledgerKey))); + new GetLedgerEntriesRequest(of(ledgerKeyToXdrBase64(ledgerKey))); SorobanRpcRequest<GetLedgerEntriesRequest> sorobanRpcRequest = gson.fromJson( recordedRequest.getBody().readUtf8(), @@ -546,9 +543,7 @@ public class SorobanServerTest { GetEventsRequest.EventFilter eventFilter = GetEventsRequest.EventFilter.builder() - .contractIds( - Collections.singletonList( - "607682f2477a6be8cdf0fdf32be13d5f25a686cc094fd93d5aa3d7b68232d0c0")) + .contractIds(of("607682f2477a6be8cdf0fdf32be13d5f25a686cc094fd93d5aa3d7b68232d0c0")) .type(EventFilterType.CONTRACT) .topic(Arrays.asList("AAAADwAAAAdDT1VOVEVSAA==", "AAAADwAAAAlpbmNyZW1lbnQAAAA=")) .build(); @@ -851,7 +846,7 @@ public class SorobanServerTest { ((InvokeHostFunctionOperation) transaction.getOperations()[0]).getHostFunction()) .sourceAccount(transaction.getOperations()[0].getSourceAccount()) .auth( - Collections.singletonList( + of( sorobanAuthorizationEntryFromXdrBase64( "AAAAAAAAAAAAAAABxYsr+8TwVOcyT2vyDK0+Am5Bu60abSDD19SRje0WVBEAAAAJaW5jcmVtZW50AAAAAAAAAgAAABIAAAAAAAAAAFi3xKLI8peqjz0kcSgf38zsr+SOVmMxPsGOEqc+ypihAAAAAwAAAAoAAAAA"))) .build(); @@ -970,7 +965,7 @@ public class SorobanServerTest { ((InvokeHostFunctionOperation) transaction.getOperations()[0]).getHostFunction()) .sourceAccount(transaction.getOperations()[0].getSourceAccount()) .auth( - Collections.singletonList( + of( sorobanAuthorizationEntryFromXdrBase64( "AAAAAAAAAAAAAAABxYsr+8TwVOcyT2vyDK0+Am5Bu60abSDD19SRje0WVBEAAAAJaW5jcmVtZW50AAAAAAAAAgAAABIAAAAAAAAAAFi3xKLI8peqjz0kcSgf38zsr+SOVmMxPsGOEqc+ypihAAAAAwAAAAoAAAAA"))) .build(); @@ -1059,7 +1054,7 @@ public class SorobanServerTest { .build()) .build(); - Transaction transaction = buildSorobanTransaction(null, Collections.singletonList(auth)); + Transaction transaction = buildSorobanTransaction(null, of(auth)); MockWebServer mockWebServer = new MockWebServer(); Dispatcher dispatcher = @@ -1098,11 +1093,7 @@ public class SorobanServerTest { .hostFunction( ((InvokeHostFunctionOperation) transaction.getOperations()[0]).getHostFunction()) .sourceAccount(transaction.getOperations()[0].getSourceAccount()) - .auth( - Arrays.asList( - auth, - sorobanAuthorizationEntryFromXdrBase64( - "AAAAAAAAAAAAAAABxYsr+8TwVOcyT2vyDK0+Am5Bu60abSDD19SRje0WVBEAAAAJaW5jcmVtZW50AAAAAAAAAgAAABIAAAAAAAAAAFi3xKLI8peqjz0kcSgf38zsr+SOVmMxPsGOEqc+ypihAAAAAwAAAAoAAAAA"))) + .auth(of(auth)) .build(); Transaction expectedTx = new Transaction(
https://github.com/stellar/java-stellar-sdk.gitdiff --git a/src/main/java/org/stellar/sdk/SorobanServer.java b/src/main/java/org/stellar/sdk/SorobanServer.java
gitbug-java_data_gradle-common-custom-user-data-gradle-plugin.json_1
diff --git a/src/main/java/com/gradle/Utils.java b/src/main/java/com/gradle/Utils.java index e96500e..1c068c4 100644 --- a/src/main/java/com/gradle/Utils.java +++ b/src/main/java/com/gradle/Utils.java @@ -29,7 +29,7 @@ import java.util.regex.Pattern; final class Utils { - private static final Pattern GIT_REPO_URI_PATTERN = Pattern.compile("^(?:(?:https://|git://)|(?:ssh)?.*?@)(.*?(?:github|gitlab).*?)(?:/|:[0-9]*?/|:)(.*?)(?:\\.git)?$"); + private static final Pattern GIT_REPO_URI_PATTERN = Pattern.compile("^(?:(?:https://|git://)(?:.+:.+@)?|(?:ssh)?.*?@)(.*?(?:github|gitlab).*?)(?:/|:[0-9]*?/|:)(.*?)(?:\\.git)?$"); static Optional<String> sysPropertyOrEnvVariable(String sysPropertyName, String envVarName, ProviderFactory providers) { Optional<String> sysProperty = sysProperty(sysPropertyName, providers); diff --git a/src/test/java/com/gradle/UtilsTest.java b/src/test/java/com/gradle/UtilsTest.java index a161a6c..2395a19 100644 --- a/src/test/java/com/gradle/UtilsTest.java +++ b/src/test/java/com/gradle/UtilsTest.java @@ -1,22 +1,64 @@ package com.gradle; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.ArgumentsProvider; +import org.junit.jupiter.params.provider.ArgumentsSource; import java.net.URI; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; import static com.gradle.Utils.toWebRepoUri; import static org.junit.jupiter.api.Assertions.assertEquals; public class UtilsTest { - @Test - public void toWebRepoUri_git() { - assertEquals(URI.create("https://github.com/acme-inc/my-project"), toWebRepoUri("git://github.com/acme-inc/my-project.git").get()); - assertEquals(URI.create("https://gitlab.com/acme-inc/my-project"), toWebRepoUri("git://gitlab.com/acme-inc/my-project.git").get()); + + @ParameterizedTest + @ArgumentsSource(WebRepoUriArgumentsProvider.class) + public void testToWebRepoUri(String repositoryHost, String repositoryUri) { + URI expectedWebRepoUri = URI.create(String.format("https://%s.com/acme-inc/my-project", repositoryHost)); + assertEquals(Optional.of(expectedWebRepoUri), toWebRepoUri(String.format(repositoryUri, repositoryHost))); + } + + @ParameterizedTest + @ArgumentsSource(EnterpriseWebRepoUriArgumentsProvider.class) + public void testToWebRepoUri_enterpriseUri(String repositoryHost, String repositoryUri) { + URI expectedWebRepoUri = URI.create(String.format("https://%s.acme.com/acme-inc/my-project", repositoryHost)); + assertEquals(Optional.of(expectedWebRepoUri), toWebRepoUri(String.format(repositoryUri, repositoryHost))); } - @Test - public void toWebRepoUri_https() { - assertEquals(URI.create("https://github.com/acme-inc/my-project"), toWebRepoUri("https://github.com/acme-inc/my-project").get()); - assertEquals(URI.create("https://gitlab.com/acme-inc/my-project"), toWebRepoUri("https://gitlab.com/acme-inc/my-project").get()); + private static class WebRepoUriArgumentsProvider implements ArgumentsProvider { + + @Override + public Stream<? extends Arguments> provideArguments(ExtensionContext context) { + Set<String> host = Stream.of("github", "gitlab").collect(Collectors.toSet()); + Set<String> remoteRepositoryUris = Stream.of( + "https://%s.com/acme-inc/my-project", + "https://%s.com:443/acme-inc/my-project", + "https://user:secret@%s.com/acme-inc/my-project", + "ssh://git@%s.com/acme-inc/my-project.git", + "ssh://git@%s.com:22/acme-inc/my-project.git", + "git://%s.com/acme-inc/my-project.git", + "git@%s.com/acme-inc/my-project.git" + ).collect(Collectors.toSet()); + return host.stream().flatMap(h -> remoteRepositoryUris.stream().map(r -> Arguments.arguments(h, r))); + } + } + + private static class EnterpriseWebRepoUriArgumentsProvider implements ArgumentsProvider { + + @Override + public Stream<? extends Arguments> provideArguments(ExtensionContext context) { + Set<String> host = Stream.of("github", "gitlab").collect(Collectors.toSet()); + Set<String> remoteRepositoryUris = Stream.of( + "https://%s.acme.com/acme-inc/my-project", + "git@%s.acme.com/acme-inc/my-project.git" + ).collect(Collectors.toSet()); + return host.stream().flatMap(h -> remoteRepositoryUris.stream().map(r -> Arguments.arguments(h, r))); + } } }
https://github.com/gradle/common-custom-user-data-gradle-plugin.gitdiff --git a/src/main/java/com/gradle/Utils.java b/src/main/java/com/gradle/Utils.java
gitbug-java_data_w3c-epubcheck.json_1
diff --git a/src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java b/src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java index 9fc2495..0338efa 100644 --- a/src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java +++ b/src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java @@ -565,7 +565,7 @@ public class OPFChecker30 extends OPFChecker public static boolean isBlessedAudioType(String type) { - return type.equals("audio/mpeg") || type.equals("audio/mp4") || type.equals("audio/opus"); + return type.equals("audio/mpeg") || type.equals("audio/mp4") || type.matches("audio/ogg\\s*;\\s*codecs=opus"); } public static boolean isVideoType(String type) diff --git a/src/main/java/com/adobe/epubcheck/ops/OPSHandler30.java b/src/main/java/com/adobe/epubcheck/ops/OPSHandler30.java index 290a042..7e48144 100644 --- a/src/main/java/com/adobe/epubcheck/ops/OPSHandler30.java +++ b/src/main/java/com/adobe/epubcheck/ops/OPSHandler30.java @@ -644,6 +644,14 @@ public class OPSHandler30 extends OPSHandler // remove any params from the given MIME type string mimetype = MIMEType.removeParams(mimetype); + // hack: remove the codecs parameter in the resource type for OPUS audio + // so that the equality check works + // TODO remove this when we implement proper MIME type parsing + if (resourceMimetype != null && resourceMimetype.matches("audio/ogg\\s*;\\s*codecs=opus")) + { + resourceMimetype = "audio/ogg"; + } + // report any MIME type mismatch as a warning if (resourceMimetype != null && !resourceMimetype.equals(mimetype)) { diff --git a/src/test/resources/epub3/03-resources/files/resources-cmt-audio-opus-valid/EPUB/content_001.xhtml b/src/test/resources/epub3/03-resources/files/resources-cmt-audio-opus-valid/EPUB/content_001.xhtml index b25c450..a48e30a 100644 --- a/src/test/resources/epub3/03-resources/files/resources-cmt-audio-opus-valid/EPUB/content_001.xhtml +++ b/src/test/resources/epub3/03-resources/files/resources-cmt-audio-opus-valid/EPUB/content_001.xhtml @@ -7,6 +7,8 @@ <body> <h1>Loomings</h1> <p>Call me Ishmael.</p> - <audio src="audio.opus" /> + <audio> + <source src="audio.opus" type="audio/ogg; codecs=opus"/> + </audio> </body> </html> diff --git a/src/test/resources/epub3/03-resources/files/resources-cmt-audio-opus-valid/EPUB/package.opf b/src/test/resources/epub3/03-resources/files/resources-cmt-audio-opus-valid/EPUB/package.opf index 07049c3..2d677f7 100644 --- a/src/test/resources/epub3/03-resources/files/resources-cmt-audio-opus-valid/EPUB/package.opf +++ b/src/test/resources/epub3/03-resources/files/resources-cmt-audio-opus-valid/EPUB/package.opf @@ -9,7 +9,7 @@ <manifest> <item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml"/> <item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/> - <item id="audio" href="audio.opus" media-type="audio/opus"/> + <item id="audio" href="audio.opus" media-type="audio/ogg ; codecs=opus"/> </manifest> <spine> <itemref idref="content_001" />
https://github.com/w3c/epubcheck.gitdiff --git a/src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java b/src/main/java/com/adobe/epubcheck/opf/OPFChecker30.java
gitbug-java_data_w3c-epubcheck.json_2
diff --git a/src/main/java/org/w3c/epubcheck/core/references/ResourceReferencesChecker.java b/src/main/java/org/w3c/epubcheck/core/references/ResourceReferencesChecker.java index 21074cb..2f1dd08 100755 --- a/src/main/java/org/w3c/epubcheck/core/references/ResourceReferencesChecker.java +++ b/src/main/java/org/w3c/epubcheck/core/references/ResourceReferencesChecker.java @@ -43,6 +43,7 @@ import com.adobe.epubcheck.opf.OPFChecker; import com.adobe.epubcheck.opf.OPFChecker30; import com.adobe.epubcheck.opf.ValidationContext; import com.adobe.epubcheck.util.EPUBVersion; +import com.adobe.epubcheck.util.FeatureEnum; import com.google.common.base.Preconditions; import io.mola.galimatias.URL; @@ -108,6 +109,9 @@ public class ResourceReferencesChecker private void checkReference(Reference reference) { + // Report the reference + report.info(reference.location.getPath(), FeatureEnum.RESOURCE, container.relativize(reference.url)); + // Retrieve the target resource Optional<Resource> targetResource = resourceRegistry.getResource(reference.targetResource); try diff --git a/src/test/resources/reporting/json-report.feature b/src/test/resources/reporting/json-report.feature index 3d53596..9f02693 100644 --- a/src/test/resources/reporting/json-report.feature +++ b/src/test/resources/reporting/json-report.feature @@ -13,6 +13,14 @@ Then the JSON report is valid And JSON at '$.items' contains 5 items And JSON at '$..checkSum' has no null values + + ## References + + Scenario: cross-HTML references + When checking EPUB 'minimal' + Then the JSON report is valid + And JSON at '$..items[?(@.id=="nav")].referencedItems[0]' is: + | EPUB/content_001.xhtml | ## Layout
https://github.com/w3c/epubcheck.gitdiff --git a/src/main/java/org/w3c/epubcheck/core/references/ResourceReferencesChecker.java b/src/main/java/org/w3c/epubcheck/core/references/ResourceReferencesChecker.java
gitbug-java_data_w3c-epubcheck.json_3
diff --git a/src/main/java/com/adobe/epubcheck/tool/EpubChecker.java b/src/main/java/com/adobe/epubcheck/tool/EpubChecker.java index d92493c..bd38ac8 100644 --- a/src/main/java/com/adobe/epubcheck/tool/EpubChecker.java +++ b/src/main/java/com/adobe/epubcheck/tool/EpubChecker.java @@ -92,6 +92,7 @@ public class EpubChecker File listChecksOut; File customMessageFile; boolean listChecks = false; + boolean displayHelpOrVersion = false; boolean useCustomMessageFile = false; boolean failOnWarnings = false; private Messages messages = Messages.getInstance(); @@ -138,6 +139,10 @@ public class EpubChecker dumpMessageDictionary(report); return 0; } + if (displayHelpOrVersion) + { + return 0; + } if (useCustomMessageFile) { report.setCustomMessageFile(customMessageFile.getAbsolutePath()); @@ -487,7 +492,7 @@ public class EpubChecker setCustomMessageFileFromEnvironment(); Pattern argPattern = Pattern.compile("--?(.*)"); - + for (int i = 0; i < args.length; i++) { Matcher argMatch = argPattern.matcher(args[i]); @@ -738,9 +743,11 @@ public class EpubChecker case "?": case "help": displayHelp(); // display help message + displayHelpOrVersion = true; break; case "version": displayVersion(); + displayHelpOrVersion = true; break; default: System.err.println(String.format(messages.get("unrecognized_argument"), args[i])); @@ -789,7 +796,7 @@ public class EpubChecker if (path == null) { - if (listChecks) + if (listChecks || displayHelpOrVersion) { return true; } diff --git a/src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java b/src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java index 529027c..b7dc202 100644 --- a/src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java +++ b/src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java @@ -180,7 +180,7 @@ public class CommandLineTest * Validate that the -out parameter will generate a well formed xml output. * * @throws Exception - * Any parsing errors will be thrown as an exception. + * Any parsing errors will be thrown as an exception. */ @Test public void outputXMLReportTest() @@ -206,7 +206,7 @@ public class CommandLineTest * unpacked epubs. * * @throws Exception - * Any parsing errors will be thrown as an exception. + * Any parsing errors will be thrown as an exception. */ @Test public void outputXMLModeExpandedReportTest() @@ -244,7 +244,7 @@ public class CommandLineTest * get a correct xml output report with the output flag. * * @throws Exception - * Any parsing errors will be thrown as an exception. + * Any parsing errors will be thrown as an exception. */ @Test public void quietRunWithOutputTest() @@ -378,9 +378,8 @@ public class CommandLineTest @Test public void helpMessageTest1() { - runCommandLineTest(1, "-?"); - assertEquals("Command output not as expected", messages.get("no_file_specified"), - errContent.toString().trim()); + runCommandLineTest(0, "-?"); + assertEquals("", errContent.toString().trim()); String expected = String.format(messages.get("help_text").replaceAll("[\\s]+", " "), EpubCheck.version()); String actual = outContent.toString(); @@ -395,9 +394,8 @@ public class CommandLineTest @Test public void helpMessageTest2() { - runCommandLineTest(1, "-help"); - assertEquals("Command output not as expected", messages.get("no_file_specified"), - errContent.toString().trim()); + runCommandLineTest(0, "-help"); + assertEquals("", errContent.toString().trim()); String expected = String.format(messages.get("help_text").replaceAll("[\\s]+", " "), EpubCheck.version()); String actual = outContent.toString(); @@ -412,9 +410,8 @@ public class CommandLineTest @Test public void helpMessageTest3() { - runCommandLineTest(1, "--help"); - assertEquals("Command output not as expected", messages.get("no_file_specified"), - errContent.toString().trim()); + runCommandLineTest(0, "--help"); + assertEquals("", errContent.toString().trim()); String expected = String.format(messages.get("help_text").replaceAll("[\\s]+", " "), EpubCheck.version()); String actual = outContent.toString(); @@ -428,9 +425,8 @@ public class CommandLineTest @Test public void versionDisplayTest1() { - runCommandLineTest(1, "--version"); - assertEquals("Command output not as expected", messages.get("no_file_specified"), - errContent.toString().trim()); + runCommandLineTest(0, "--version"); + assertEquals("", errContent.toString().trim()); String expected = String.format( messages.get("epubcheck_version_text").replaceAll("[\\s]+", " "), EpubCheck.version()); String actual = outContent.toString(); @@ -444,9 +440,8 @@ public class CommandLineTest @Test public void versionDisplayTest2() { - runCommandLineTest(1, "-version"); - assertEquals("Command output not as expected", messages.get("no_file_specified"), - errContent.toString().trim()); + runCommandLineTest(0, "-version"); + assertEquals("", errContent.toString().trim()); String expected = String.format( messages.get("epubcheck_version_text").replaceAll("[\\s]+", " "), EpubCheck.version()); String actual = outContent.toString(); @@ -689,7 +684,7 @@ public class CommandLineTest * document. * * @throws Exception - * Throws an exception if the temp file can't be created. + * Throws an exception if the temp file can't be created. */ @Test public void jsonFileTest() @@ -714,7 +709,7 @@ public class CommandLineTest * document. * * @throws Exception - * Any parsing errors will be thrown as an exception. + * Any parsing errors will be thrown as an exception. */ @Test public void xmlFileTest() @@ -740,7 +735,7 @@ public class CommandLineTest * document. * * @throws Exception - * Any parsing errors will be thrown as an exception. + * Any parsing errors will be thrown as an exception. */ @Test public void xmpFileTest()
https://github.com/w3c/epubcheck.gitdiff --git a/src/main/java/com/adobe/epubcheck/tool/EpubChecker.java b/src/main/java/com/adobe/epubcheck/tool/EpubChecker.java
gitbug-java_data_gitbucket-markedj.json_1
diff --git a/src/main/java/io/github/gitbucket/markedj/Grammer.java b/src/main/java/io/github/gitbucket/markedj/Grammer.java index f7f2312..a9945d1 100644 --- a/src/main/java/io/github/gitbucket/markedj/Grammer.java +++ b/src/main/java/io/github/gitbucket/markedj/Grammer.java @@ -77,7 +77,7 @@ public class Grammer { public static String INLINE_ESCAPE = "^\\\\([\\\\`*{}\\[\\]()#+\\-.!_>])"; public static String INLINE_TEXT = "^[\\s\\S]+?(?=[\\\\<!\\[_*`]| {2,}\\n|$)"; - public static String INLINE_BR = "^ {2,}\\n(?!\\s*$)"; + public static String INLINE_BR = "^( {2,}|\\\\)\\n(?!\\s*$)"; static { INLINE_RULES.put("escape", new FindFirstRule(INLINE_ESCAPE)); diff --git a/src/test/java/io/github/gitbucket/markedj/MarkedTest.java b/src/test/java/io/github/gitbucket/markedj/MarkedTest.java index e5efd61..f14a857 100644 --- a/src/test/java/io/github/gitbucket/markedj/MarkedTest.java +++ b/src/test/java/io/github/gitbucket/markedj/MarkedTest.java @@ -264,4 +264,20 @@ public class MarkedTest { in.close(); } } + + @Test + public void testHardLineBreakWithSpaces() { + String result = Marked.marked("Line 1 \n" + + "Line 2"); + assertEquals("<p>Line 1<br>\n" + + " Line 2</p>", result); + } + + @Test + public void testHardLineBreakWithBackslash() { + String result = Marked.marked("Line 1\\\n" + + "Line 2"); + assertEquals("<p>Line 1<br>\n" + + " Line 2</p>", result); + } }
https://github.com/gitbucket/markedj.gitdiff --git a/src/main/java/io/github/gitbucket/markedj/Grammer.java b/src/main/java/io/github/gitbucket/markedj/Grammer.java
gitbug-java_data_fishercoder1534-Leetcode.json_1
diff --git a/src/main/java/com/fishercoder/solutions/_235.java b/src/main/java/com/fishercoder/solutions/_235.java index 97b70d3..d470efd 100644 --- a/src/main/java/com/fishercoder/solutions/_235.java +++ b/src/main/java/com/fishercoder/solutions/_235.java @@ -9,10 +9,9 @@ public class _235 { if (root == null || p == root || q == root) { return root; } - if ((root.val - p.val) * (root.val - q.val) > 0) { - if (root.val - p.val > 0) { - return lowestCommonAncestor(root.left, p, q); - } + if (root.val > p.val && root.val > q.val) { + return lowestCommonAncestor(root.left, p, q); + } else if (root.val < p.val && root.val < q.val) { return lowestCommonAncestor(root.right, p, q); } return root; diff --git a/src/test/java/com/fishercoder/_235Test.java b/src/test/java/com/fishercoder/_235Test.java index ef01b11..4fcb0f7 100644 --- a/src/test/java/com/fishercoder/_235Test.java +++ b/src/test/java/com/fishercoder/_235Test.java @@ -49,4 +49,18 @@ public class _235Test { assertEquals(p, solution1.lowestCommonAncestor(root, p, q)); } + + @Test + public void test3() { + root = TreeUtils.constructBinaryTree(Arrays.asList(0, -1000000000, 1000000000)); + TreeUtils.printBinaryTree(root); + + p = TreeUtils.constructBinaryTree(Arrays.asList(-1000000000)); + TreeUtils.printBinaryTree(p); + + q = TreeUtils.constructBinaryTree(Arrays.asList(1000000000)); + TreeUtils.printBinaryTree(q); + + assertEquals(root, solution1.lowestCommonAncestor(root, p, q)); + } }
https://github.com/fishercoder1534/Leetcode.gitdiff --git a/src/main/java/com/fishercoder/solutions/_235.java b/src/main/java/com/fishercoder/solutions/_235.java
gitbug-java_data_Netflix-frigga.json_1
diff --git a/src/main/java/com/netflix/frigga/ami/AppVersion.java b/src/main/java/com/netflix/frigga/ami/AppVersion.java index c712415..fc82d53 100644 --- a/src/main/java/com/netflix/frigga/ami/AppVersion.java +++ b/src/main/java/com/netflix/frigga/ami/AppVersion.java @@ -33,7 +33,7 @@ public class AppVersion implements Comparable<AppVersion> { */ private static final Pattern APP_VERSION_PATTERN = Pattern.compile( "([" + NameConstants.NAME_HYPHEN_CHARS - + "]+)-([0-9.a-zA-Z~]+)-(\\w+)(?:[.](\\w+))?(?:\\/([" + NameConstants.NAME_HYPHEN_CHARS + "]+)\\/([0-9]+))?"); + + "]+)-([0-9.a-zA-Z~]+)-(\\w+)(?:[.](\\w+))?(?:~[" + NameConstants.NAME_HYPHEN_CHARS + "]+)?(?:\\/([" + NameConstants.NAME_HYPHEN_CHARS + "]+)\\/([0-9]+))?"); private String packageName; diff --git a/src/test/groovy/com/netflix/frigga/ami/AppVersionTest.groovy b/src/test/groovy/com/netflix/frigga/ami/AppVersionTest.groovy index 22082a4..eec2a12 100644 --- a/src/test/groovy/com/netflix/frigga/ami/AppVersionTest.groovy +++ b/src/test/groovy/com/netflix/frigga/ami/AppVersionTest.groovy @@ -113,12 +113,15 @@ class AppVersionTest extends Specification { appversionString | packageName | version | commit | buildNumber | buildJob 'appName-0.1-9b3bc237.h150' | 'appName' | '0.1' | '9b3bc237' | '150' | null 'appName-0.1-9b3bc237.h150' | 'appName' | '0.1' | '9b3bc237' | '150' | null + 'appName-0.1-h150.9b3bc237~focal' | 'appName' | '0.1' | '9b3bc237' | '150' | null + 'appName-0.1-h150.9b3bc237~focal/mybuild/150' | 'appName' | '0.1' | '9b3bc237' | '150' | 'mybuild' 'appName-0.1b34-9b3bc237.h150' | 'appName' | '0.1b34' | '9b3bc237' | '150' | null 'appName-0.1-1630379' | 'appName' | '0.1' | '1630379' | null | null 'appName-0.1-1' | 'appName' | '0.1' | '1' | null | null 'appName-0.1-abcd6789' | 'appName' | '0.1' | 'abcd6789' | null | null 'appName-0.1~rc.1-1630379' | 'appName' | '0.1~rc.1' | '1630379' | null | null 'appName-0.1~dev.1-9b3bc237.h150' | 'appName' | '0.1~dev.1' | '9b3bc237' | '150' | null + 'appName-0.1~dev.1-h150.9b3bc237~focal' | 'appName' | '0.1~dev.1' | '9b3bc237' | '150' | null 'appName-0.1~dev.3.uncommitted-h0.54f3416' | 'appName' | '0.1~dev.3.uncommitted' | '54f3416' | '0' | null 'testApp-1.3.0-h196/mybuild/196' | 'testApp' | '1.3.0' | null | '196' | 'mybuild' 'testApp-1.3.0-h196.9b3bc237/mybuild/196' | 'testApp' | '1.3.0' | '9b3bc237' | '196' | 'mybuild'
https://github.com/Netflix/frigga.gitdiff --git a/src/main/java/com/netflix/frigga/ami/AppVersion.java b/src/main/java/com/netflix/frigga/ami/AppVersion.java
gitbug-java_data_mthmulders-mcs.json_1
diff --git a/src/main/java/it/mulders/mcs/common/Result.java b/src/main/java/it/mulders/mcs/common/Result.java index ad7b46d..297a29b 100644 --- a/src/main/java/it/mulders/mcs/common/Result.java +++ b/src/main/java/it/mulders/mcs/common/Result.java @@ -21,6 +21,11 @@ public sealed interface Result<T> permits Result.Success, Result.Failure { } @Override + public void ifPresentOrElse(Consumer<T> successConsumer, Consumer<Throwable> failureConsumer) { + successConsumer.accept(value); + } + + @Override public Throwable cause() { throw new NoSuchElementException("success: " + this.value); } @@ -37,6 +42,11 @@ public sealed interface Result<T> permits Result.Success, Result.Failure { } @Override + public void ifPresentOrElse(Consumer<T> successConsumer, Consumer<Throwable> failureConsumer) { + failureConsumer.accept(cause); + } + + @Override public T value() { throw new NoSuchElementException("failure: " + this.cause.getLocalizedMessage()); } @@ -46,6 +56,8 @@ public sealed interface Result<T> permits Result.Success, Result.Failure { void ifPresent(final Consumer<T> consumer); + void ifPresentOrElse(final Consumer<T> successConsumer, final Consumer<Throwable> failureConsumer); + T value(); Throwable cause(); diff --git a/src/main/java/it/mulders/mcs/search/SearchCommandHandler.java b/src/main/java/it/mulders/mcs/search/SearchCommandHandler.java index f68a0d0..3dcba38 100644 --- a/src/main/java/it/mulders/mcs/search/SearchCommandHandler.java +++ b/src/main/java/it/mulders/mcs/search/SearchCommandHandler.java @@ -27,7 +27,10 @@ public class SearchCommandHandler { public void search(final SearchQuery query) { performSearch(query) .map(response -> performAdditionalSearch(query, response)) - .ifPresent(response -> printResponse(query, response)); + .ifPresentOrElse( + response -> printResponse(query, response), + failure -> { throw new RuntimeException(failure); } + ); } private SearchResponse.Response performAdditionalSearch(final SearchQuery query, diff --git a/src/test/java/it/mulders/mcs/search/SearchCommandHandlerTest.java b/src/test/java/it/mulders/mcs/search/SearchCommandHandlerTest.java index b73ad75..278eb9c 100644 --- a/src/test/java/it/mulders/mcs/search/SearchCommandHandlerTest.java +++ b/src/test/java/it/mulders/mcs/search/SearchCommandHandlerTest.java @@ -9,6 +9,8 @@ import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import javax.net.ssl.SSLHandshakeException; + import static org.mockito.Mockito.any; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.mock; @@ -35,6 +37,9 @@ class SearchCommandHandlerTest implements WithAssertions { private final SearchClient searchClient = new SearchClient() { @Override public Result<SearchResponse> search(final SearchQuery query) { + if (query.toSolrQuery().contains("tls-error")) { + return new Result.Failure<>(new SSLHandshakeException("PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target")); + } if (query instanceof WildcardSearchQuery) { return new Result.Success<>(new SearchResponse(null, wildcardResponse)); } else if (query instanceof CoordinateQuery cq && cq.version().isBlank()) { @@ -55,6 +60,12 @@ class SearchCommandHandlerTest implements WithAssertions { handler.search(SearchQuery.search("plexus-utils").build()); verify(outputPrinter).print(any(WildcardSearchQuery.class), eq(wildcardResponse), any()); } + + @Test + void should_propagate_tls_exception_to_runtime_exception() { + assertThatThrownBy(() -> handler.search(SearchQuery.search("tls-error").build())) + .isInstanceOf(RuntimeException.class); + } } @Nested @@ -77,5 +88,11 @@ class SearchCommandHandlerTest implements WithAssertions { handler.search(SearchQuery.search("org.codehaus.plexus:plexus-utils:3.4.1").build()); verify(outputPrinter).print(any(CoordinateQuery.class), eq(threePartCoordinateResponse), any()); } + + @Test + void should_propagate_tls_exception_to_runtime_exception() { + assertThatThrownBy(() -> handler.search(SearchQuery.search("org.codehaus.plexus:tls-error:3.4.1").build())) + .isInstanceOf(RuntimeException.class); + } } } \ No newline at end of file
https://github.com/mthmulders/mcs.gitdiff --git a/src/main/java/it/mulders/mcs/common/Result.java b/src/main/java/it/mulders/mcs/common/Result.java
gitbug-java_data_mthmulders-mcs.json_2
diff --git a/src/main/java/it/mulders/mcs/search/printer/BuildrOutput.java b/src/main/java/it/mulders/mcs/search/printer/BuildrOutput.java index 81299ac..74c7ddc 100644 --- a/src/main/java/it/mulders/mcs/search/printer/BuildrOutput.java +++ b/src/main/java/it/mulders/mcs/search/printer/BuildrOutput.java @@ -3,7 +3,7 @@ package it.mulders.mcs.search.printer; public final class BuildrOutput implements CoordinatePrinter { @Override - public String provideCoordinates(final String group, final String artifact, final String version) { + public String provideCoordinates(final String group, final String artifact, final String version, String packaging) { return "'%s:%s:jar:%s'".formatted(group, artifact, version); } } diff --git a/src/main/java/it/mulders/mcs/search/printer/CoordinatePrinter.java b/src/main/java/it/mulders/mcs/search/printer/CoordinatePrinter.java index fb98f4c..9e27fb9 100644 --- a/src/main/java/it/mulders/mcs/search/printer/CoordinatePrinter.java +++ b/src/main/java/it/mulders/mcs/search/printer/CoordinatePrinter.java @@ -9,7 +9,7 @@ public sealed interface CoordinatePrinter extends OutputPrinter permits BuildrOutput, GradleGroovyOutput, GradleGroovyShortOutput, GradleKotlinOutput, GrapeOutput, IvyXmlOutput, LeiningenOutput, PomXmlOutput, SbtOutput { - String provideCoordinates(final String group, final String artifact, final String version); + String provideCoordinates(final String group, final String artifact, final String version, final String packaging); @Override default void print(final SearchQuery query, final SearchResponse.Response response, final PrintStream stream) { @@ -19,7 +19,7 @@ public sealed interface CoordinatePrinter extends OutputPrinter var doc = response.docs()[0]; stream.println(); - stream.println(provideCoordinates(doc.g(), doc.a(), first(doc.v(), doc.latestVersion()))); + stream.println(provideCoordinates(doc.g(), doc.a(), first(doc.v(), doc.latestVersion()), doc.p())); stream.println(); } diff --git a/src/main/java/it/mulders/mcs/search/printer/GradleGroovyOutput.java b/src/main/java/it/mulders/mcs/search/printer/GradleGroovyOutput.java index 653ddaf..21edd9f 100644 --- a/src/main/java/it/mulders/mcs/search/printer/GradleGroovyOutput.java +++ b/src/main/java/it/mulders/mcs/search/printer/GradleGroovyOutput.java @@ -3,7 +3,7 @@ package it.mulders.mcs.search.printer; public final class GradleGroovyOutput implements CoordinatePrinter { @Override - public String provideCoordinates(final String group, final String artifact, final String version) { + public String provideCoordinates(final String group, final String artifact, final String version, String packaging) { return "implementation group: '%s', name: '%s', version: '%s'".formatted(group, artifact, version); } } diff --git a/src/main/java/it/mulders/mcs/search/printer/GradleGroovyShortOutput.java b/src/main/java/it/mulders/mcs/search/printer/GradleGroovyShortOutput.java index dd74a11..041b066 100644 --- a/src/main/java/it/mulders/mcs/search/printer/GradleGroovyShortOutput.java +++ b/src/main/java/it/mulders/mcs/search/printer/GradleGroovyShortOutput.java @@ -3,7 +3,7 @@ package it.mulders.mcs.search.printer; public final class GradleGroovyShortOutput implements CoordinatePrinter { @Override - public String provideCoordinates(final String group, final String artifact, final String version) { + public String provideCoordinates(final String group, final String artifact, final String version, String packaging) { return "implementation '%s:%s:%s'".formatted(group, artifact, version); } } diff --git a/src/main/java/it/mulders/mcs/search/printer/GradleKotlinOutput.java b/src/main/java/it/mulders/mcs/search/printer/GradleKotlinOutput.java index 0dede3a..5db3031 100644 --- a/src/main/java/it/mulders/mcs/search/printer/GradleKotlinOutput.java +++ b/src/main/java/it/mulders/mcs/search/printer/GradleKotlinOutput.java @@ -3,7 +3,7 @@ package it.mulders.mcs.search.printer; public final class GradleKotlinOutput implements CoordinatePrinter { @Override - public String provideCoordinates(final String group, final String artifact, final String version) { + public String provideCoordinates(final String group, final String artifact, final String version, String packaging) { return "implementation(\"%s:%s:%s\")".formatted(group, artifact, version); } } diff --git a/src/main/java/it/mulders/mcs/search/printer/GrapeOutput.java b/src/main/java/it/mulders/mcs/search/printer/GrapeOutput.java index cbea0d4..692fa7f 100644 --- a/src/main/java/it/mulders/mcs/search/printer/GrapeOutput.java +++ b/src/main/java/it/mulders/mcs/search/printer/GrapeOutput.java @@ -3,7 +3,7 @@ package it.mulders.mcs.search.printer; public final class GrapeOutput implements CoordinatePrinter { @Override - public String provideCoordinates(final String group, final String artifact, final String version) { + public String provideCoordinates(final String group, final String artifact, final String version, String packaging) { return """ @Grapes( @Grab(group='%s', module='%s', version='%s') diff --git a/src/main/java/it/mulders/mcs/search/printer/IvyXmlOutput.java b/src/main/java/it/mulders/mcs/search/printer/IvyXmlOutput.java index 995c15d..4ade67d 100644 --- a/src/main/java/it/mulders/mcs/search/printer/IvyXmlOutput.java +++ b/src/main/java/it/mulders/mcs/search/printer/IvyXmlOutput.java @@ -3,7 +3,7 @@ package it.mulders.mcs.search.printer; public final class IvyXmlOutput implements CoordinatePrinter { @Override - public String provideCoordinates(final String group, final String artifact, final String version) { + public String provideCoordinates(final String group, final String artifact, final String version, String packaging) { return """ <dependency org="%s" name="%s" rev="%s"/> """.formatted(group, artifact, version); diff --git a/src/main/java/it/mulders/mcs/search/printer/LeiningenOutput.java b/src/main/java/it/mulders/mcs/search/printer/LeiningenOutput.java index 2f150cf..b3bdcfa 100644 --- a/src/main/java/it/mulders/mcs/search/printer/LeiningenOutput.java +++ b/src/main/java/it/mulders/mcs/search/printer/LeiningenOutput.java @@ -3,7 +3,7 @@ package it.mulders.mcs.search.printer; public final class LeiningenOutput implements CoordinatePrinter { @Override - public String provideCoordinates(final String group, final String artifact, final String version) { + public String provideCoordinates(final String group, final String artifact, final String version, String packaging) { return "[%s/%s \"%s\"]".formatted(group, artifact, version); } } diff --git a/src/main/java/it/mulders/mcs/search/printer/PomXmlOutput.java b/src/main/java/it/mulders/mcs/search/printer/PomXmlOutput.java index 68474f7..f34c46c 100644 --- a/src/main/java/it/mulders/mcs/search/printer/PomXmlOutput.java +++ b/src/main/java/it/mulders/mcs/search/printer/PomXmlOutput.java @@ -3,13 +3,14 @@ package it.mulders.mcs.search.printer; public final class PomXmlOutput implements CoordinatePrinter { @Override - public String provideCoordinates(final String group, final String artifact, final String version) { + public String provideCoordinates(final String group, final String artifact, final String version, String packaging) { + String element = "maven-plugin".equals(packaging) ? "plugin" : "dependency"; return """ - <dependency> + <%4$s> <groupId>%s</groupId> <artifactId>%s</artifactId> <version>%s</version> - </dependency> - """.formatted(group, artifact, version); + </%4$s> + """.formatted(group, artifact, version, element); } } diff --git a/src/main/java/it/mulders/mcs/search/printer/SbtOutput.java b/src/main/java/it/mulders/mcs/search/printer/SbtOutput.java index f4c57e8..9ff8894 100644 --- a/src/main/java/it/mulders/mcs/search/printer/SbtOutput.java +++ b/src/main/java/it/mulders/mcs/search/printer/SbtOutput.java @@ -3,7 +3,7 @@ package it.mulders.mcs.search.printer; public final class SbtOutput implements CoordinatePrinter { @Override - public String provideCoordinates(final String group, final String artifact, final String version) { + public String provideCoordinates(final String group, final String artifact, final String version, String packaging) { return """ libraryDependencies += "%s" %% "%s" %% "%s" """.formatted(group, artifact, version); diff --git a/src/test/java/it/mulders/mcs/search/printer/CoordinatePrinterTest.java b/src/test/java/it/mulders/mcs/search/printer/CoordinatePrinterTest.java index 5f0fdbb..395eb03 100644 --- a/src/test/java/it/mulders/mcs/search/printer/CoordinatePrinterTest.java +++ b/src/test/java/it/mulders/mcs/search/printer/CoordinatePrinterTest.java @@ -14,6 +14,17 @@ import java.util.stream.Stream; class CoordinatePrinterTest implements WithAssertions { private static final SearchQuery QUERY = SearchQuery.search("org.codehaus.plexus:plexus-utils").build(); + private static final SearchResponse.Response PLUGIN_RESPONSE = new SearchResponse.Response(1, 0, new SearchResponse.Response.Doc[]{ + new SearchResponse.Response.Doc( + "org.apache.maven.plugins:maven-jar-plugin:3.3.0", + "org.apache.maven.plugins", + "maven-jar-plugin", + "3.3.0", + null, + "maven-plugin", + 1630022910000L + ) + }); private static final SearchResponse.Response RESPONSE = new SearchResponse.Response(1, 0, new SearchResponse.Response.Doc[]{ new SearchResponse.Response.Doc( @@ -26,13 +37,20 @@ class CoordinatePrinterTest implements WithAssertions { 1630022910000L ) }); - private static final String POM_XML_OUTPUT = """ + private static final String POM_XML_DEPENDENCY_OUTPUT = """ <dependency> <groupId>org.codehaus.plexus</groupId> <artifactId>plexus-utils</artifactId> <version>3.4.1</version> </dependency> """; + private static final String POM_XML_PLUGIN_OUTPUT = """ + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <version>3.3.0</version> + </plugin> + """; private static final String GRADLE_GROOVY_OUTPUT = "implementation group: 'org.codehaus.plexus', name: 'plexus-utils', version: '3.4.1'"; private static final String GRADLE_GROOVY_SHORT_OUTPUT = "implementation 'org.codehaus.plexus:plexus-utils:3.4.1'"; private static final String GRADLE_KOTLIN_OUTPUT = "implementation(\"org.codehaus.plexus:plexus-utils:3.4.1\")"; @@ -54,22 +72,23 @@ class CoordinatePrinterTest implements WithAssertions { private static Stream<Arguments> coordinatePrinters() { return Stream.of( - Arguments.of(new PomXmlOutput(), POM_XML_OUTPUT), - Arguments.of(new GradleGroovyOutput(), GRADLE_GROOVY_OUTPUT), - Arguments.of(new GradleGroovyShortOutput(), GRADLE_GROOVY_SHORT_OUTPUT), - Arguments.of(new GradleKotlinOutput(), GRADLE_KOTLIN_OUTPUT), - Arguments.of(new SbtOutput(), SBT_OUTPUT), - Arguments.of(new IvyXmlOutput(), IVY_XML_OUTPUT), - Arguments.of(new GrapeOutput(), GRAPE_OUTPUT), - Arguments.of(new LeiningenOutput(), LEININGEN_OUTPUT), - Arguments.of(new BuildrOutput(), BUILDR_OUTPUT) + Arguments.of(new PomXmlOutput(), POM_XML_DEPENDENCY_OUTPUT, RESPONSE), + Arguments.of(new PomXmlOutput(), POM_XML_PLUGIN_OUTPUT, PLUGIN_RESPONSE), + Arguments.of(new GradleGroovyOutput(), GRADLE_GROOVY_OUTPUT, RESPONSE), + Arguments.of(new GradleGroovyShortOutput(), GRADLE_GROOVY_SHORT_OUTPUT, RESPONSE), + Arguments.of(new GradleKotlinOutput(), GRADLE_KOTLIN_OUTPUT, RESPONSE), + Arguments.of(new SbtOutput(), SBT_OUTPUT, RESPONSE), + Arguments.of(new IvyXmlOutput(), IVY_XML_OUTPUT, RESPONSE), + Arguments.of(new GrapeOutput(), GRAPE_OUTPUT, RESPONSE), + Arguments.of(new LeiningenOutput(), LEININGEN_OUTPUT, RESPONSE), + Arguments.of(new BuildrOutput(), BUILDR_OUTPUT, RESPONSE) ); } @ParameterizedTest @MethodSource("coordinatePrinters") - void should_print_snippet(CoordinatePrinter printer, String expected) { - printer.print(QUERY, RESPONSE, new PrintStream(buffer)); + void should_print_snippet(CoordinatePrinter printer, String expected, SearchResponse.Response response) { + printer.print(QUERY, response, new PrintStream(buffer)); var xml = buffer.toString(); assertThat(xml).isEqualToIgnoringWhitespace(expected);
https://github.com/mthmulders/mcs.gitdiff --git a/src/main/java/it/mulders/mcs/search/printer/BuildrOutput.java b/src/main/java/it/mulders/mcs/search/printer/BuildrOutput.java
gitbug-java_data_mthmulders-mcs.json_3
diff --git a/src/main/java/it/mulders/mcs/search/printer/TabularOutputPrinter.java b/src/main/java/it/mulders/mcs/search/printer/TabularOutputPrinter.java index c36b641..58022f5 100644 --- a/src/main/java/it/mulders/mcs/search/printer/TabularOutputPrinter.java +++ b/src/main/java/it/mulders/mcs/search/printer/TabularOutputPrinter.java @@ -61,6 +61,6 @@ public class TabularOutputPrinter implements OutputPrinter { Instant.ofEpochMilli(doc.timestamp()).atZone(ZoneId.systemDefault()) ); - table.addRowValues(doc.id(), lastUpdated); + table.addRowValues(doc.id() + ":" + doc.latestVersion(), lastUpdated); } } diff --git a/src/test/java/it/mulders/mcs/search/printer/TabularOutputPrinterTest.java b/src/test/java/it/mulders/mcs/search/printer/TabularOutputPrinterTest.java index 8fbc1ea..6e605dd 100644 --- a/src/test/java/it/mulders/mcs/search/printer/TabularOutputPrinterTest.java +++ b/src/test/java/it/mulders/mcs/search/printer/TabularOutputPrinterTest.java @@ -41,7 +41,7 @@ class TabularOutputPrinterTest implements WithAssertions { // Assert var table = buffer.toString(); - assertThat(table).contains("org.codehaus.plexus:plexus-utils"); + assertThat(table).contains("org.codehaus.plexus:plexus-utils:3.4.1"); } @Test
https://github.com/mthmulders/mcs.gitdiff --git a/src/main/java/it/mulders/mcs/search/printer/TabularOutputPrinter.java b/src/main/java/it/mulders/mcs/search/printer/TabularOutputPrinter.java
gitbug-java_data_aws-aws-secretsmanager-jdbc.json_1
diff --git a/src/main/java/com/amazonaws/secretsmanager/sql/AWSSecretsManagerPostgreSQLDriver.java b/src/main/java/com/amazonaws/secretsmanager/sql/AWSSecretsManagerPostgreSQLDriver.java index bfd2d6d..8af0071 100644 --- a/src/main/java/com/amazonaws/secretsmanager/sql/AWSSecretsManagerPostgreSQLDriver.java +++ b/src/main/java/com/amazonaws/secretsmanager/sql/AWSSecretsManagerPostgreSQLDriver.java @@ -116,8 +116,11 @@ public final class AWSSecretsManagerPostgreSQLDriver extends AWSSecretsManagerDr if (!StringUtils.isNullOrEmpty(port)) { url += ":" + port; } + + url += "/"; + if (!StringUtils.isNullOrEmpty(dbname)) { - url += "/" + dbname; + url += dbname; } return url; } diff --git a/src/test/java/com/amazonaws/secretsmanager/sql/AWSSecretsManagerPostgreSQLDriverTest.java b/src/test/java/com/amazonaws/secretsmanager/sql/AWSSecretsManagerPostgreSQLDriverTest.java index d6239dd..a7ecf4b 100644 --- a/src/test/java/com/amazonaws/secretsmanager/sql/AWSSecretsManagerPostgreSQLDriverTest.java +++ b/src/test/java/com/amazonaws/secretsmanager/sql/AWSSecretsManagerPostgreSQLDriverTest.java @@ -93,7 +93,7 @@ public class AWSSecretsManagerPostgreSQLDriverTest extends TestClass { @Test public void test_constructUrlNullDatabase() { String url = sut.constructUrlFromEndpointPortDatabase("test-endpoint", "1234", null); - assertEquals(url, "jdbc:postgresql://test-endpoint:1234"); + assertEquals(url, "jdbc:postgresql://test-endpoint:1234/"); } @Test
https://github.com/aws/aws-secretsmanager-jdbc.gitdiff --git a/src/main/java/com/amazonaws/secretsmanager/sql/AWSSecretsManagerPostgreSQLDriver.java b/src/main/java/com/amazonaws/secretsmanager/sql/AWSSecretsManagerPostgreSQLDriver.java
gitbug-java_data_spring-projects-spring-retry.json_1
diff --git a/src/main/java/org/springframework/retry/backoff/BackOffPolicyBuilder.java b/src/main/java/org/springframework/retry/backoff/BackOffPolicyBuilder.java index da1dd8c..72c9185 100644 --- a/src/main/java/org/springframework/retry/backoff/BackOffPolicyBuilder.java +++ b/src/main/java/org/springframework/retry/backoff/BackOffPolicyBuilder.java @@ -267,7 +267,10 @@ public class BackOffPolicyBuilder { return policy; } FixedBackOffPolicy policy = new FixedBackOffPolicy(); - if (this.delay != null) { + if (this.delaySupplier != null) { + policy.backOffPeriodSupplier(this.delaySupplier); + } + else if (this.delay != null) { policy.setBackOffPeriod(this.delay); } if (this.sleeper != null) { diff --git a/src/test/java/org/springframework/retry/annotation/EnableRetryTests.java b/src/test/java/org/springframework/retry/annotation/EnableRetryTests.java index 8023263..50fd2ed 100644 --- a/src/test/java/org/springframework/retry/annotation/EnableRetryTests.java +++ b/src/test/java/org/springframework/retry/annotation/EnableRetryTests.java @@ -37,6 +37,7 @@ import org.springframework.retry.RetryCallback; import org.springframework.retry.RetryContext; import org.springframework.retry.RetryListener; import org.springframework.retry.backoff.ExponentialBackOffPolicy; +import org.springframework.retry.backoff.FixedBackOffPolicy; import org.springframework.retry.backoff.Sleeper; import org.springframework.retry.interceptor.RetryInterceptorBuilder; import org.springframework.retry.policy.SimpleRetryPolicy; @@ -257,6 +258,11 @@ public class EnableRetryTests { assertThat(retryPolicy.getMaxAttempts()).isEqualTo(5); service.service4(); assertThat(service.getCount()).isEqualTo(11); + interceptor = delegates.get(target(service)).get(ExpressionService.class.getDeclaredMethod("service4")); + template = (RetryTemplate) new DirectFieldAccessor(interceptor).getPropertyValue("retryOperations"); + templateAccessor = new DirectFieldAccessor(template); + FixedBackOffPolicy fbp = (FixedBackOffPolicy) templateAccessor.getPropertyValue("backOffPolicy"); + assertThat(fbp.getBackOffPeriod()).isEqualTo(5000L); service.service5(); assertThat(service.getCount()).isEqualTo(12); context.close(); @@ -762,7 +768,8 @@ public class EnableRetryTests { } } - @Retryable(exceptionExpression = "message.contains('this can be retried')") + @Retryable(exceptionExpression = "message.contains('this can be retried')", + backoff = @Backoff(delayExpression = "5000")) public void service4() { if (this.count++ < 10) { throw new RuntimeException("this can be retried");
https://github.com/spring-projects/spring-retry.gitdiff --git a/src/main/java/org/springframework/retry/backoff/BackOffPolicyBuilder.java b/src/main/java/org/springframework/retry/backoff/BackOffPolicyBuilder.java
gitbug-java_data_spring-projects-spring-retry.json_2
diff --git a/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java b/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java index 194f7d4..bd1f71c 100644 --- a/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java +++ b/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2022 the original author or authors. + * Copyright 2006-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,6 +41,7 @@ import org.springframework.util.ClassUtils; * @author Dave Syer * @author Gary Russell * @author Artem Bilan + * @author Marius Lichtblau */ @SuppressWarnings("serial") public class ExponentialBackOffPolicy implements SleepingBackOffPolicy<ExponentialBackOffPolicy> { @@ -245,6 +246,7 @@ public class ExponentialBackOffPolicy implements SleepingBackOffPolicy<Exponenti this.sleeper.sleep(sleepTime); } catch (InterruptedException e) { + Thread.currentThread().interrupt(); throw new BackOffInterruptedException("Thread interrupted while sleeping", e); } } diff --git a/src/main/java/org/springframework/retry/backoff/FixedBackOffPolicy.java b/src/main/java/org/springframework/retry/backoff/FixedBackOffPolicy.java index db12bb9..fc26986 100644 --- a/src/main/java/org/springframework/retry/backoff/FixedBackOffPolicy.java +++ b/src/main/java/org/springframework/retry/backoff/FixedBackOffPolicy.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2022 the original author or authors. + * Copyright 2006-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,6 +31,7 @@ import org.springframework.util.Assert; * @author Rob Harrop * @author Dave Syer * @author Artem Bilan + * @author Marius Lichtblau */ public class FixedBackOffPolicy extends StatelessBackOffPolicy implements SleepingBackOffPolicy<FixedBackOffPolicy> { @@ -97,6 +98,7 @@ public class FixedBackOffPolicy extends StatelessBackOffPolicy implements Sleepi sleeper.sleep(this.backOffPeriod.get()); } catch (InterruptedException e) { + Thread.currentThread().interrupt(); throw new BackOffInterruptedException("Thread interrupted while sleeping", e); } } diff --git a/src/main/java/org/springframework/retry/backoff/UniformRandomBackOffPolicy.java b/src/main/java/org/springframework/retry/backoff/UniformRandomBackOffPolicy.java index ef696d8..68249f7 100644 --- a/src/main/java/org/springframework/retry/backoff/UniformRandomBackOffPolicy.java +++ b/src/main/java/org/springframework/retry/backoff/UniformRandomBackOffPolicy.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2022 the original author or authors. + * Copyright 2006-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,6 +32,7 @@ import org.springframework.util.Assert; * @author Rob Harrop * @author Dave Syer * @author Tomaz Fernandes + * @author Marius Lichtblau */ public class UniformRandomBackOffPolicy extends StatelessBackOffPolicy implements SleepingBackOffPolicy<UniformRandomBackOffPolicy> { @@ -138,6 +139,7 @@ public class UniformRandomBackOffPolicy extends StatelessBackOffPolicy this.sleeper.sleep(min + delta); } catch (InterruptedException e) { + Thread.currentThread().interrupt(); throw new BackOffInterruptedException("Thread interrupted while sleeping", e); } } diff --git a/src/test/java/org/springframework/retry/backoff/ExponentialBackOffPolicyTests.java b/src/test/java/org/springframework/retry/backoff/ExponentialBackOffPolicyTests.java index ab63a4f..294203d 100644 --- a/src/test/java/org/springframework/retry/backoff/ExponentialBackOffPolicyTests.java +++ b/src/test/java/org/springframework/retry/backoff/ExponentialBackOffPolicyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2022 the original author or authors. + * Copyright 2006-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,11 +19,13 @@ package org.springframework.retry.backoff; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * @author Rob Harrop * @author Dave Syer * @author Gary Russell + * @author Marius Lichtblau */ public class ExponentialBackOffPolicyTests { @@ -92,4 +94,18 @@ public class ExponentialBackOffPolicyTests { } } + @Test + public void testInterruptedStatusIsRestored() { + ExponentialBackOffPolicy strategy = new ExponentialBackOffPolicy(); + strategy.setSleeper(new Sleeper() { + @Override + public void sleep(long backOffPeriod) throws InterruptedException { + throw new InterruptedException("foo"); + } + }); + BackOffContext context = strategy.start(null); + assertThatExceptionOfType(BackOffInterruptedException.class).isThrownBy(() -> strategy.backOff(context)); + assertThat(Thread.interrupted()).isTrue(); + } + } diff --git a/src/test/java/org/springframework/retry/backoff/FixedBackOffPolicyTests.java b/src/test/java/org/springframework/retry/backoff/FixedBackOffPolicyTests.java index 5ca7091..f57c1e7 100644 --- a/src/test/java/org/springframework/retry/backoff/FixedBackOffPolicyTests.java +++ b/src/test/java/org/springframework/retry/backoff/FixedBackOffPolicyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2022 the original author or authors. + * Copyright 2006-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,11 +19,13 @@ package org.springframework.retry.backoff; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * @author Rob Harrop * @author Dave Syer * @author Gary Russell + * @author Marius Lichtblau * @since 2.1 */ public class FixedBackOffPolicyTests { @@ -65,4 +67,19 @@ public class FixedBackOffPolicyTests { assertThat(sleeper.getBackOffs().length).isEqualTo(10); } + @Test + public void testInterruptedStatusIsRestored() { + int backOffPeriod = 50; + FixedBackOffPolicy strategy = new FixedBackOffPolicy(); + strategy.setBackOffPeriod(backOffPeriod); + strategy.setSleeper(new Sleeper() { + @Override + public void sleep(long backOffPeriod) throws InterruptedException { + throw new InterruptedException("foo"); + } + }); + assertThatExceptionOfType(BackOffInterruptedException.class).isThrownBy(() -> strategy.backOff(null)); + assertThat(Thread.interrupted()).isTrue(); + } + } diff --git a/src/test/java/org/springframework/retry/backoff/UniformRandomBackOffPolicyTests.java b/src/test/java/org/springframework/retry/backoff/UniformRandomBackOffPolicyTests.java index 1dd3095..0ea1838 100644 --- a/src/test/java/org/springframework/retry/backoff/UniformRandomBackOffPolicyTests.java +++ b/src/test/java/org/springframework/retry/backoff/UniformRandomBackOffPolicyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2022 the original author or authors. + * Copyright 2006-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,10 +19,12 @@ package org.springframework.retry.backoff; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * @author Tomaz Fernandes * @author Gary Russell + * @author Marius Lichtblau * @since 1.3.2 */ public class UniformRandomBackOffPolicyTests { @@ -40,4 +42,22 @@ public class UniformRandomBackOffPolicyTests { assertThat(withSleeper.getMaxBackOffPeriod()).isEqualTo(maxBackOff); } + @Test + public void testInterruptedStatusIsRestored() { + UniformRandomBackOffPolicy backOffPolicy = new UniformRandomBackOffPolicy(); + int minBackOff = 1000; + int maxBackOff = 10000; + backOffPolicy.setMinBackOffPeriod(minBackOff); + backOffPolicy.setMaxBackOffPeriod(maxBackOff); + UniformRandomBackOffPolicy withSleeper = backOffPolicy.withSleeper(new Sleeper() { + @Override + public void sleep(long backOffPeriod) throws InterruptedException { + throw new InterruptedException("foo"); + } + }); + + assertThatExceptionOfType(BackOffInterruptedException.class).isThrownBy(() -> withSleeper.backOff(null)); + assertThat(Thread.interrupted()).isTrue(); + } + }
https://github.com/spring-projects/spring-retry.gitdiff --git a/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java b/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java
gitbug-java_data_ballerina-platform-lsp4intellij.json_1
diff --git a/src/main/java/org/wso2/lsp4intellij/utils/FileUtils.java b/src/main/java/org/wso2/lsp4intellij/utils/FileUtils.java index 01c1edd..9231c7d 100644 --- a/src/main/java/org/wso2/lsp4intellij/utils/FileUtils.java +++ b/src/main/java/org/wso2/lsp4intellij/utils/FileUtils.java @@ -198,12 +198,7 @@ public class FileUtils { * @return the URI */ public static String VFSToURI(VirtualFile file) { - try { - return sanitizeURI(new URL(file.getUrl().replace(" ", SPACE_ENCODED)).toURI().toString()); - } catch (MalformedURLException | URISyntaxException e) { - LOG.warn(e); - return null; - } + return file == null? null : pathToUri(file.getPath()); } /** @@ -286,7 +281,7 @@ public class FileUtils { * @return The uri */ public static String pathToUri(@Nullable String path) { - return path != null ? sanitizeURI(new File(path.replace(" ", SPACE_ENCODED)).toURI().toString()) : null; + return path != null ? sanitizeURI(new File(path).toURI().toString()) : null; } public static String projectToUri(Project project) { diff --git a/src/test/java/org/wso2/lsp4intellij/utils/FileUtilsTest.java b/src/test/java/org/wso2/lsp4intellij/utils/FileUtilsTest.java index f074b4e..f38eede 100644 --- a/src/test/java/org/wso2/lsp4intellij/utils/FileUtilsTest.java +++ b/src/test/java/org/wso2/lsp4intellij/utils/FileUtilsTest.java @@ -101,8 +101,13 @@ public class FileUtilsTest { } @Test - public void testVFSToURINull() { - Assert.assertNull(FileUtils.VFSToURI((new LightVirtualFile()))); + public void testVFSToURINotNull() { + // LightVirtualFile returns '/' as path + String uri = FileUtils.VFSToURI((new LightVirtualFile())); + Assert.assertNotNull(uri); + + String expectedUri = OSUtils.isWindows() ? "file:///C:/" : "file:///"; + Assert.assertEquals(expectedUri, uri); } @Test
https://github.com/ballerina-platform/lsp4intellij.gitdiff --git a/src/main/java/org/wso2/lsp4intellij/utils/FileUtils.java b/src/main/java/org/wso2/lsp4intellij/utils/FileUtils.java
gitbug-java_data_dmak-jaxb-xew-plugin.json_1
diff --git a/src/main/java/com/sun/tools/xjc/addon/xew/XmlElementWrapperPlugin.java b/src/main/java/com/sun/tools/xjc/addon/xew/XmlElementWrapperPlugin.java index f8e9fcc..8131336 100644 --- a/src/main/java/com/sun/tools/xjc/addon/xew/XmlElementWrapperPlugin.java +++ b/src/main/java/com/sun/tools/xjc/addon/xew/XmlElementWrapperPlugin.java @@ -904,12 +904,18 @@ public class XmlElementWrapperPlugin extends AbstractConfigurablePlugin { } } - if (classes.containsKey(clazz.name())) { - writeSummary("\tRenaming class " + clazz.fullName() + " to class " + parent.name() + clazz.name()); - setPrivateField(clazz, "name", parent.name() + clazz.name()); + // Rename the class in case there is class name collision. + // FIXME: Should that be doublechecked after renaming? + if (classes.containsKey(clazz.name()) || classes.containsKey(clazz.name().toUpperCase())) { + String newName = parent.name() + clazz.name(); + writeSummary("\tRenaming class " + clazz.fullName() + " to class " + newName); + setPrivateField(clazz, "name", newName); } - classes.put(clazz.name(), clazz); + // Special treatment for the case when "classes" map holds class names in upper case + // (true for case-sensitive filesystems, see usages of JCodeModel.isCaseSensitiveFileSystem): + boolean allClassNamesInUpperCase = classes.keySet().stream().allMatch(key -> key.equals(key.toUpperCase())); + classes.put(allClassNamesInUpperCase ? clazz.name().toUpperCase() : clazz.name(), clazz); // Finally modify the class so that it refers back the container: setPrivateField(clazz, "outer", grandParent); diff --git a/src/test/generated_resources/inner_scoped_element/Catalogue.java b/src/test/generated_resources/inner_scoped_element/Catalogue.java index da83bf3..bd7e319 100644 --- a/src/test/generated_resources/inner_scoped_element/Catalogue.java +++ b/src/test/generated_resources/inner_scoped_element/Catalogue.java @@ -1,140 +1,140 @@ - -package inner_scoped_element; - -import java.util.ArrayList; -import java.util.List; -import jakarta.xml.bind.JAXBElement; -import jakarta.xml.bind.annotation.XmlAccessType; -import jakarta.xml.bind.annotation.XmlAccessorType; -import jakarta.xml.bind.annotation.XmlElement; -import jakarta.xml.bind.annotation.XmlElementRef; -import jakarta.xml.bind.annotation.XmlElementRefs; -import jakarta.xml.bind.annotation.XmlElementWrapper; -import jakarta.xml.bind.annotation.XmlRootElement; -import jakarta.xml.bind.annotation.XmlType; - - -/** - * <p>Java class for anonymous complex type. - * - * <p>The following schema fragment specifies the expected content contained within this class. - * - * <pre> - * &lt;complexType&gt; - * &lt;complexContent&gt; - * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt; - * &lt;sequence&gt; - * &lt;element name="stockage_collection"&gt; - * &lt;complexType&gt; - * &lt;complexContent&gt; - * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt; - * &lt;sequence minOccurs="0"&gt; - * &lt;element name="stockage" maxOccurs="unbounded" minOccurs="0"&gt; - * &lt;complexType&gt; - * &lt;complexContent&gt; - * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt; - * &lt;all&gt; - * &lt;element name="collection" minOccurs="0"&gt; - * &lt;complexType&gt; - * &lt;complexContent&gt; - * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt; - * &lt;sequence maxOccurs="unbounded" minOccurs="0"&gt; - * &lt;element name="effect" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt; - * &lt;element name="term" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt; - * &lt;/sequence&gt; - * &lt;/restriction&gt; - * &lt;/complexContent&gt; - * &lt;/complexType&gt; - * &lt;/element&gt; - * &lt;/all&gt; - * &lt;/restriction&gt; - * &lt;/complexContent&gt; - * &lt;/complexType&gt; - * &lt;/element&gt; - * &lt;/sequence&gt; - * &lt;/restriction&gt; - * &lt;/complexContent&gt; - * &lt;/complexType&gt; - * &lt;/element&gt; - * &lt;/sequence&gt; - * &lt;/restriction&gt; - * &lt;/complexContent&gt; - * &lt;/complexType&gt; - * </pre> - * - * - */ -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "", propOrder = { - "stockageCollection" -}) -@XmlRootElement(name = "catalogue") -public class Catalogue { - - @XmlElementWrapper(name = "stockage_collection", required = true) - @XmlElement(name = "stockage") - protected List<Catalogue.Stockage> stockageCollection = new ArrayList<Catalogue.Stockage>(); - - public List<Catalogue.Stockage> getStockageCollection() { - return stockageCollection; - } - - public void setStockageCollection(List<Catalogue.Stockage> stockageCollection) { - this.stockageCollection = stockageCollection; - } - - - /** - * <p>Java class for anonymous complex type. - * - * <p>The following schema fragment specifies the expected content contained within this class. - * - * <pre> - * &lt;complexType&gt; - * &lt;complexContent&gt; - * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt; - * &lt;all&gt; - * &lt;element name="collection" minOccurs="0"&gt; - * &lt;complexType&gt; - * &lt;complexContent&gt; - * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt; - * &lt;sequence maxOccurs="unbounded" minOccurs="0"&gt; - * &lt;element name="effect" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt; - * &lt;element name="term" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt; - * &lt;/sequence&gt; - * &lt;/restriction&gt; - * &lt;/complexContent&gt; - * &lt;/complexType&gt; - * &lt;/element&gt; - * &lt;/all&gt; - * &lt;/restriction&gt; - * &lt;/complexContent&gt; - * &lt;/complexType&gt; - * </pre> - * - * - */ - @XmlAccessorType(XmlAccessType.FIELD) - @XmlType(name = "", propOrder = { - - }) - public static class Stockage { - - @XmlElementWrapper - @XmlElementRefs({ - @XmlElementRef(name = "effect", type = JAXBElement.class, required = false), - @XmlElementRef(name = "term", type = JAXBElement.class, required = false) - }) - protected List<JAXBElement<String>> collection = new ArrayList<JAXBElement<String>>(); - - public List<JAXBElement<String>> getCollection() { - return collection; - } - - public void setCollection(List<JAXBElement<String>> collection) { - this.collection = collection; - } - - } - -} + +package inner_scoped_element; + +import java.util.ArrayList; +import java.util.List; +import jakarta.xml.bind.JAXBElement; +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; +import jakarta.xml.bind.annotation.XmlElement; +import jakarta.xml.bind.annotation.XmlElementRef; +import jakarta.xml.bind.annotation.XmlElementRefs; +import jakarta.xml.bind.annotation.XmlElementWrapper; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; + + +/** + * <p>Java class for anonymous complex type. + * + * <p>The following schema fragment specifies the expected content contained within this class. + * + * <pre> + * &lt;complexType&gt; + * &lt;complexContent&gt; + * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt; + * &lt;sequence&gt; + * &lt;element name="stockage"&gt; + * &lt;complexType&gt; + * &lt;complexContent&gt; + * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt; + * &lt;sequence minOccurs="0"&gt; + * &lt;element name="stockage" maxOccurs="unbounded" minOccurs="0"&gt; + * &lt;complexType&gt; + * &lt;complexContent&gt; + * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt; + * &lt;all&gt; + * &lt;element name="collection" minOccurs="0"&gt; + * &lt;complexType&gt; + * &lt;complexContent&gt; + * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt; + * &lt;sequence maxOccurs="unbounded" minOccurs="0"&gt; + * &lt;element name="effect" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt; + * &lt;element name="term" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt; + * &lt;/sequence&gt; + * &lt;/restriction&gt; + * &lt;/complexContent&gt; + * &lt;/complexType&gt; + * &lt;/element&gt; + * &lt;/all&gt; + * &lt;/restriction&gt; + * &lt;/complexContent&gt; + * &lt;/complexType&gt; + * &lt;/element&gt; + * &lt;/sequence&gt; + * &lt;/restriction&gt; + * &lt;/complexContent&gt; + * &lt;/complexType&gt; + * &lt;/element&gt; + * &lt;/sequence&gt; + * &lt;/restriction&gt; + * &lt;/complexContent&gt; + * &lt;/complexType&gt; + * </pre> + * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + "stockage" +}) +@XmlRootElement(name = "catalogue") +public class Catalogue { + + @XmlElementWrapper(required = true) + @XmlElement(name = "stockage") + protected List<Catalogue.StockageStockage> stockage = new ArrayList<Catalogue.StockageStockage>(); + + public List<Catalogue.StockageStockage> getStockage() { + return stockage; + } + + public void setStockage(List<Catalogue.StockageStockage> stockage) { + this.stockage = stockage; + } + + + /** + * <p>Java class for anonymous complex type. + * + * <p>The following schema fragment specifies the expected content contained within this class. + * + * <pre> + * &lt;complexType&gt; + * &lt;complexContent&gt; + * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt; + * &lt;all&gt; + * &lt;element name="collection" minOccurs="0"&gt; + * &lt;complexType&gt; + * &lt;complexContent&gt; + * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType"&gt; + * &lt;sequence maxOccurs="unbounded" minOccurs="0"&gt; + * &lt;element name="effect" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt; + * &lt;element name="term" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/&gt; + * &lt;/sequence&gt; + * &lt;/restriction&gt; + * &lt;/complexContent&gt; + * &lt;/complexType&gt; + * &lt;/element&gt; + * &lt;/all&gt; + * &lt;/restriction&gt; + * &lt;/complexContent&gt; + * &lt;/complexType&gt; + * </pre> + * + * + */ + @XmlAccessorType(XmlAccessType.FIELD) + @XmlType(name = "", propOrder = { + + }) + public static class StockageStockage { + + @XmlElementWrapper + @XmlElementRefs({ + @XmlElementRef(name = "effect", type = JAXBElement.class, required = false), + @XmlElementRef(name = "term", type = JAXBElement.class, required = false) + }) + protected List<JAXBElement<String>> collection = new ArrayList<JAXBElement<String>>(); + + public List<JAXBElement<String>> getCollection() { + return collection; + } + + public void setCollection(List<JAXBElement<String>> collection) { + this.collection = collection; + } + + } + +} diff --git a/src/test/generated_resources/inner_scoped_element/ObjectFactory.java b/src/test/generated_resources/inner_scoped_element/ObjectFactory.java index 685a398..ff0d391 100644 --- a/src/test/generated_resources/inner_scoped_element/ObjectFactory.java +++ b/src/test/generated_resources/inner_scoped_element/ObjectFactory.java @@ -1,63 +1,63 @@ - -package inner_scoped_element; - -import javax.xml.namespace.QName; -import jakarta.xml.bind.JAXBElement; -import jakarta.xml.bind.annotation.XmlElementDecl; -import jakarta.xml.bind.annotation.XmlRegistry; - - -/** - * This object contains factory methods for each - * Java content interface and Java element interface - * generated in the inner_scoped_element package. - * <p>An ObjectFactory allows you to programatically - * construct new instances of the Java representation - * for XML content. The Java representation of XML - * content can consist of schema derived interfaces - * and classes representing the binding of schema - * type definitions, element declarations and model - * groups. Factory methods for each of these are - * provided in this class. - * - */ -@XmlRegistry -public class ObjectFactory { - - private final static QName _CatalogueStockageCollectionStockageCollectionEffect_QNAME = new QName("", "effect"); - private final static QName _CatalogueStockageCollectionStockageCollectionTerm_QNAME = new QName("", "term"); - - /** - * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: inner_scoped_element - * - */ - public ObjectFactory() { - } - - /** - * Create an instance of {@link Catalogue } - * - */ - public Catalogue createCatalogue() { - return new Catalogue(); - } - - /** - * Create an instance of {@link Catalogue.Stockage } - * - */ - public Catalogue.Stockage createCatalogueStockage() { - return new Catalogue.Stockage(); - } - - @XmlElementDecl(namespace = "", name = "effect", scope = Catalogue.Stockage.class) - public JAXBElement<String> createCatalogueStockageEffect(String value) { - return new JAXBElement<String>(new QName("", "effect"), String.class, Catalogue.Stockage.class, value); - } - - @XmlElementDecl(namespace = "", name = "term", scope = Catalogue.Stockage.class) - public JAXBElement<String> createCatalogueStockageTerm(String value) { - return new JAXBElement<String>(new QName("", "term"), String.class, Catalogue.Stockage.class, value); - } - -} + +package inner_scoped_element; + +import javax.xml.namespace.QName; +import jakarta.xml.bind.JAXBElement; +import jakarta.xml.bind.annotation.XmlElementDecl; +import jakarta.xml.bind.annotation.XmlRegistry; + + +/** + * This object contains factory methods for each + * Java content interface and Java element interface + * generated in the inner_scoped_element package. + * <p>An ObjectFactory allows you to programatically + * construct new instances of the Java representation + * for XML content. The Java representation of XML + * content can consist of schema derived interfaces + * and classes representing the binding of schema + * type definitions, element declarations and model + * groups. Factory methods for each of these are + * provided in this class. + * + */ +@XmlRegistry +public class ObjectFactory { + + private final static QName _CatalogueStockageStockageCollectionEffect_QNAME = new QName("", "effect"); + private final static QName _CatalogueStockageStockageCollectionTerm_QNAME = new QName("", "term"); + + /** + * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: inner_scoped_element + * + */ + public ObjectFactory() { + } + + /** + * Create an instance of {@link Catalogue } + * + */ + public Catalogue createCatalogue() { + return new Catalogue(); + } + + /** + * Create an instance of {@link Catalogue.StockageStockage } + * + */ + public Catalogue.StockageStockage createCatalogueStockageStockage() { + return new Catalogue.StockageStockage(); + } + + @XmlElementDecl(namespace = "", name = "effect", scope = Catalogue.StockageStockage.class) + public JAXBElement<String> createCatalogueStockageStockageEffect(String value) { + return new JAXBElement<String>(new QName("", "effect"), String.class, Catalogue.StockageStockage.class, value); + } + + @XmlElementDecl(namespace = "", name = "term", scope = Catalogue.StockageStockage.class) + public JAXBElement<String> createCatalogueStockageStockageTerm(String value) { + return new JAXBElement<String>(new QName("", "term"), String.class, Catalogue.StockageStockage.class, value); + } + +} diff --git a/src/test/resources/com/sun/tools/xjc/addon/xew/inner-scoped-element.xml b/src/test/resources/com/sun/tools/xjc/addon/xew/inner-scoped-element.xml index 9d8d955..f8f948d 100644 --- a/src/test/resources/com/sun/tools/xjc/addon/xew/inner-scoped-element.xml +++ b/src/test/resources/com/sun/tools/xjc/addon/xew/inner-scoped-element.xml @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <catalogue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="inner-scoped-element.xsd"> - <stockage_collection> + <stockage> <stockage> <collection> <term>solar panels</term> @@ -15,5 +15,5 @@ <effect>maintenance costs</effect> </collection> </stockage> - </stockage_collection> + </stockage> </catalogue> diff --git a/src/test/resources/com/sun/tools/xjc/addon/xew/inner-scoped-element.xsd b/src/test/resources/com/sun/tools/xjc/addon/xew/inner-scoped-element.xsd index 7f2fac9..64885ae 100644 --- a/src/test/resources/com/sun/tools/xjc/addon/xew/inner-scoped-element.xsd +++ b/src/test/resources/com/sun/tools/xjc/addon/xew/inner-scoped-element.xsd @@ -16,7 +16,8 @@ <xsd:element name="catalogue"> <xsd:complexType> <xsd:sequence> - <xsd:element name="stockage_collection"> + <!-- Also tests the scenario when element/class names collide within parent class. --> + <xsd:element name="stockage"> <xsd:complexType> <xsd:sequence minOccurs="0"> <xsd:element name="stockage" minOccurs="0" maxOccurs="unbounded">
https://github.com/dmak/jaxb-xew-plugin.gitdiff --git a/src/main/java/com/sun/tools/xjc/addon/xew/XmlElementWrapperPlugin.java b/src/main/java/com/sun/tools/xjc/addon/xew/XmlElementWrapperPlugin.java
gitbug-java_data_assertj-assertj-vavr.json_1
diff --git a/src/main/java/org/assertj/vavr/api/AbstractSeqAssert.java b/src/main/java/org/assertj/vavr/api/AbstractSeqAssert.java index 7353dab..bc8d763 100644 --- a/src/main/java/org/assertj/vavr/api/AbstractSeqAssert.java +++ b/src/main/java/org/assertj/vavr/api/AbstractSeqAssert.java @@ -19,6 +19,7 @@ import org.assertj.core.api.IndexedObjectEnumerableAssert; import org.assertj.core.data.Index; import org.assertj.core.internal.ComparatorBasedComparisonStrategy; import org.assertj.core.internal.ComparisonStrategy; +import org.assertj.core.internal.Iterables; import org.assertj.core.internal.StandardComparisonStrategy; import org.assertj.core.util.CheckReturnValue; @@ -67,6 +68,7 @@ abstract class AbstractSeqAssert<SELF extends AbstractSeqAssert<SELF, ACTUAL, EL */ @CheckReturnValue public SELF usingElementComparator(Comparator<? super ELEMENT> customComparator) { + this.iterables = new Iterables(new ComparatorBasedComparisonStrategy(customComparator)); seqElementComparisonStrategy = new ComparatorBasedComparisonStrategy(customComparator); return myself; } diff --git a/src/test/java/org/assertj/vavr/api/SeqAssert_containsExactly_inAnyOrder_Test.java b/src/test/java/org/assertj/vavr/api/SeqAssert_containsExactly_inAnyOrder_Test.java index a0de5e9..3654c00 100644 --- a/src/test/java/org/assertj/vavr/api/SeqAssert_containsExactly_inAnyOrder_Test.java +++ b/src/test/java/org/assertj/vavr/api/SeqAssert_containsExactly_inAnyOrder_Test.java @@ -33,6 +33,15 @@ class SeqAssert_containsExactly_inAnyOrder_Test { } @Test + void should_pass_if_List_contains_exactly_elements_in_any_order_using_element_comparator() { + final Set<String> expectedInAnyOrder = HashSet.of("other", "and", "else", "something"); + final List<String> uppercaseList = expectedInAnyOrder.map(String::toUpperCase).toList().reverse(); + assertThat(uppercaseList) + .usingElementComparator(String::compareToIgnoreCase) + .containsExactlyInAnyOrder(expectedInAnyOrder); + } + + @Test void should_fail_when_List_is_null() { final Set<String> expectedInAnyOrder = HashSet.of("other", "and", "else", "something"); assertThatThrownBy( diff --git a/src/test/java/org/assertj/vavr/api/soft/JUnitSoftVavrAssertionsFailureTest.java b/src/test/java/org/assertj/vavr/api/soft/JUnitSoftVavrAssertionsFailureTest.java index 4fa4447..9459721 100644 --- a/src/test/java/org/assertj/vavr/api/soft/JUnitSoftVavrAssertionsFailureTest.java +++ b/src/test/java/org/assertj/vavr/api/soft/JUnitSoftVavrAssertionsFailureTest.java @@ -44,7 +44,7 @@ public class JUnitSoftVavrAssertionsFailureTest { // THEN List<Throwable> failures = multipleFailuresError.getFailures(); assertThat(failures).hasSize(2); - assertThat(failures.get(0)).hasMessageStartingWith(format("[contains] %nExpecting:%n <Left(something)>%nto contain:%n <\"else\">%nbut did not.")); + assertThat(failures.get(0)).hasMessageStartingWith(format("[contains] %nExpecting:%n <Left(something)>%nto contain:%n <\"else\"> on the [LEFT]%nbut did not.")); assertThat(failures.get(1)).hasMessageStartingWith(format("[instance] %nExpecting:%n" + " <Left>%n" + "to contain a value that is an instance of:%n" + @@ -53,4 +53,4 @@ public class JUnitSoftVavrAssertionsFailureTest { " <java.lang.String>")); } -} \ No newline at end of file +}
https://github.com/assertj/assertj-vavr.gitdiff --git a/src/main/java/org/assertj/vavr/api/AbstractSeqAssert.java b/src/main/java/org/assertj/vavr/api/AbstractSeqAssert.java
gitbug-java_data_IBM-JSONata4Java.json_1
diff --git a/src/main/java/com/api/jsonata4java/expressions/OrderByOperator.java b/src/main/java/com/api/jsonata4java/expressions/OrderByOperator.java index e8f199a..829eaf0 100644 --- a/src/main/java/com/api/jsonata4java/expressions/OrderByOperator.java +++ b/src/main/java/com/api/jsonata4java/expressions/OrderByOperator.java @@ -13,6 +13,8 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.JsonNodeFactory; import com.fasterxml.jackson.databind.node.TextNode; +import com.fasterxml.jackson.databind.node.NumericNode; +import com.fasterxml.jackson.databind.node.BooleanNode; public class OrderByOperator { @@ -35,14 +37,29 @@ public class OrderByOperator { for (final OrderByField sortField : sortFields) { JsonNode n1 = o1.get(sortField.name); JsonNode n2 = o2.get(sortField.name); - if (n1 != null && n1 instanceof TextNode - && n2 != null && n2 instanceof TextNode) { - final int comp = ((TextNode) n1).asText().compareTo(((TextNode) n2).asText()); - if (comp != 0) { - return sortField.order == OrderByOrder.DESC ? comp * (-1) : comp; + if (n1 != null && n2 != null) { + if (n1 instanceof TextNode && n2 instanceof TextNode) { + final int comp = ((TextNode) n1).asText().compareTo(((TextNode) n2).asText()); + if (comp != 0) { + return sortField.order == OrderByOrder.DESC ? comp * -1 : comp; + } } - } - } + if (n1 instanceof NumericNode && n2 instanceof NumericNode) { + final int comp = (int) Double.compare(((NumericNode) n1).asDouble(), ((NumericNode) n2).asDouble()); + if (comp != 0) { + return sortField.order == OrderByOrder.DESC ? comp * -1 : comp; + } + + } + if (n1 instanceof BooleanNode && n2 instanceof BooleanNode) { + final int comp = Boolean.compare(((BooleanNode) n1).asBoolean(), ((BooleanNode) n2).asBoolean()); + if (comp != 0) { + return sortField.order == OrderByOrder.DESC ? comp * -1 : comp; + } + + } + } + } return 0; } }); diff --git a/src/test/java/com/api/jsonata4java/test/expressions/OpOrderByTest.java b/src/test/java/com/api/jsonata4java/test/expressions/OpOrderByTest.java index 13bac7b..640c55e 100644 --- a/src/test/java/com/api/jsonata4java/test/expressions/OpOrderByTest.java +++ b/src/test/java/com/api/jsonata4java/test/expressions/OpOrderByTest.java @@ -61,4 +61,11 @@ public class OpOrderByTest { "[{\"id\":\"1\",\"content\":\"1\"},{\"id\":\"2\",\"content\":\"1\"},{\"id\":\"2\",\"content\":\"2\"}]", null, "[{\"id\":\"1\",\"content\":\"1\"},{\"id\":\"2\",\"content\":\"1\"},{\"id\":\"2\",\"content\":\"2\"}]"); } + + @Test + public void testOrderedNumeric() throws Exception { + test("$^(id, content)", + "[{\"id\":1,\"content\":\"1\"},{\"id\":2,\"content\":\"1\"},{\"id\":2,\"content\":\"2\"}]", null, + "[{\"id\":2,\"content\":\"2\"},{\"id\":2,\"content\":\"1\"},{\"id\":1,\"content\":\"1\"}]"); + } }
https://github.com/IBM/JSONata4Java.gitdiff --git a/src/main/java/com/api/jsonata4java/expressions/OrderByOperator.java b/src/main/java/com/api/jsonata4java/expressions/OrderByOperator.java
gitbug-java_data_cloudsimplus-cloudsimplus.json_1
diff --git a/src/main/java/org/cloudsimplus/hosts/HostAbstract.java b/src/main/java/org/cloudsimplus/hosts/HostAbstract.java index 19dfe5d..70d7fea 100644 --- a/src/main/java/org/cloudsimplus/hosts/HostAbstract.java +++ b/src/main/java/org/cloudsimplus/hosts/HostAbstract.java @@ -162,7 +162,7 @@ public abstract class HostAbstract extends ExecDelayableAbstract implements Host } public HostAbstract(final List<Pe> peList, final boolean activate) { - this(defaultBwCapacity, defaultStorageCapacity, new HarddriveStorage(defaultRamCapacity), peList, activate); + this(defaultRamCapacity, defaultBwCapacity, new HarddriveStorage(defaultStorageCapacity), peList, activate); } protected HostAbstract(
https://github.com/cloudsimplus/cloudsimplus.gitdiff --git a/src/main/java/org/cloudsimplus/hosts/HostAbstract.java b/src/main/java/org/cloudsimplus/hosts/HostAbstract.java
gitbug-java_data_iipc-jwarc.json_1
diff --git a/src/org/netpreserve/jwarc/cdx/CdxRequestEncoder.java b/src/org/netpreserve/jwarc/cdx/CdxRequestEncoder.java index 9ac2df3..20af855 100644 --- a/src/org/netpreserve/jwarc/cdx/CdxRequestEncoder.java +++ b/src/org/netpreserve/jwarc/cdx/CdxRequestEncoder.java @@ -28,18 +28,19 @@ public class CdxRequestEncoder { StringBuilder out = new StringBuilder(); out.append("__wb_method="); out.append(httpRequest.method()); + int maxLength = out.length() + 1 + QUERY_STRING_LIMIT; MediaType baseContentType = httpRequest.contentType().base(); InputStream stream = new BufferedInputStream(httpRequest.body().stream(), BUFFER_SIZE); if (baseContentType.equals(MediaType.WWW_FORM_URLENCODED)) { encodeFormBody(stream, out); } else if (baseContentType.equals(MediaType.JSON)) { - encodeJsonBody(stream, out, false); + encodeJsonBody(stream, out, maxLength, false); } else if (baseContentType.equals(MediaType.PLAIN_TEXT)) { - encodeJsonBody(stream, out, true); + encodeJsonBody(stream, out, maxLength, true); } else { encodeBinaryBody(stream, out); } - return out.substring(0, Math.min(out.length(), QUERY_STRING_LIMIT)); + return out.substring(0, Math.min(out.length(), maxLength)); } static void encodeBinaryBody(InputStream stream, StringBuilder out) throws IOException { @@ -61,14 +62,14 @@ public class CdxRequestEncoder { } } - private static void encodeJsonBody(InputStream stream, StringBuilder output, boolean binaryFallback) throws IOException { + private static void encodeJsonBody(InputStream stream, StringBuilder output, int maxLength, boolean binaryFallback) throws IOException { stream.mark(BUFFER_SIZE); JsonParser parser = new JsonFactory().createParser(stream); Map<String,Long> nameCounts = new HashMap<>(); Deque<String> nameStack = new ArrayDeque<>(); String name = null; try { - while (parser.nextToken() != null && output.length() < QUERY_STRING_LIMIT) { + while (parser.nextToken() != null && output.length() < maxLength) { switch (parser.currentToken()) { case FIELD_NAME: name = parser.getCurrentName(); diff --git a/test/org/netpreserve/jwarc/cdx/CdxRequestEncoderTest.java b/test/org/netpreserve/jwarc/cdx/CdxRequestEncoderTest.java index 95cc314..6d14354 100644 --- a/test/org/netpreserve/jwarc/cdx/CdxRequestEncoderTest.java +++ b/test/org/netpreserve/jwarc/cdx/CdxRequestEncoderTest.java @@ -12,6 +12,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardOpenOption; import java.util.Arrays; +import java.util.Collections; import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.Assert.assertEquals; @@ -47,26 +48,44 @@ public class CdxRequestEncoderTest { new Case("__wb_method=POST&a=2", MediaType.PLAIN_TEXT, "{\"a\":2}"), new Case("__wb_method=POST&__wb_post_data=bm90IGpzb24=", - MediaType.PLAIN_TEXT, "not json") + MediaType.PLAIN_TEXT, "not json"), + new Case("__wb_method=POST&" + ("bigtext=" + + String.join("+", Collections.nCopies(1000, "this+is+very+long"))).substring(0, 4096), + MediaType.JSON, "{\"bigtext\": \"" + + String.join(" ", Collections.nCopies(1000, "this is very long")) + "\"}", "x=1"), }; public static class Case { final String expected; final MediaType requestType; final byte[] requestBody; + final String queryString; public Case(String expected, MediaType requestType, String requestBody) { this(expected, requestType, requestBody.getBytes(UTF_8)); } + public Case(String expected, MediaType requestType, String requestBody, String queryString) { + this(expected, requestType, requestBody.getBytes(UTF_8), queryString); + } + public Case(String expected, MediaType requestType, byte[] requestBody) { + this(expected, requestType, requestBody, null); + } + + public Case(String expected, MediaType requestType, byte[] requestBody, String queryString) { this.expected = expected; this.requestType = requestType; this.requestBody = requestBody; + this.queryString = queryString; } public HttpRequest request() { - return new HttpRequest.Builder("POST", "/foo") + String target = "/foo"; + if (queryString != null) { + target += "?" + queryString; + } + return new HttpRequest.Builder("POST", target) .body(requestType, requestBody) .build(); } @@ -114,8 +133,10 @@ public class CdxRequestEncoderTest { String[] params = queryString.split("&"); Arrays.sort(params); String sortedQueryString = String.join("&", params); - String expectedKey = URIs.toNormalizedSurt("http://example" + cases[i].request().target() + "?" + - cases[i].expected).replaceFirst(".*\\?", ""); + String target = cases[i].request().target(); + String expectedSurt = URIs.toNormalizedSurt("http://example" + target + + (target.contains("?") ? "&" : "?") + cases[i].expected); + String expectedKey = expectedSurt.replaceFirst(".*\\?", ""); assertEquals("Case " + i, expectedKey, sortedQueryString); } } finally {
https://github.com/iipc/jwarc.gitdiff --git a/src/org/netpreserve/jwarc/cdx/CdxRequestEncoder.java b/src/org/netpreserve/jwarc/cdx/CdxRequestEncoder.java
gitbug-java_data_iipc-jwarc.json_2
diff --git a/src/org/netpreserve/jwarc/WarcParser.java b/src/org/netpreserve/jwarc/WarcParser.java index 7207246..753d66d 100644 --- a/src/org/netpreserve/jwarc/WarcParser.java +++ b/src/org/netpreserve/jwarc/WarcParser.java @@ -20,7 +20,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.US_ASCII; -// line 147 "WarcParser.rl" +// line 142 "WarcParser.rl" /** @@ -243,30 +243,23 @@ case 1: case 10: // line 80 "WarcParser.rl" { - // TODO + setHeader("Content-Length", new String(buf, 0, bufPos, US_ASCII)); bufPos = 0; } break; case 11: // line 85 "WarcParser.rl" { - setHeader("Content-Length", new String(buf, 0, bufPos, US_ASCII)); - bufPos = 0; -} - break; - case 12: -// line 90 "WarcParser.rl" - { protocol = "ARC"; major = 1; minor = 1; } break; - case 13: -// line 145 "WarcParser.rl" + case 12: +// line 140 "WarcParser.rl" { { p += 1; _goto_targ = 5; if (true) continue _goto;} } break; -// line 270 "WarcParser.java" +// line 263 "WarcParser.java" } } } @@ -286,7 +279,7 @@ case 5: break; } } -// line 209 "WarcParser.rl" +// line 204 "WarcParser.rl" position += p - data.position(); data.position(p); @@ -340,14 +333,13 @@ case 5: } -// line 344 "WarcParser.java" +// line 337 "WarcParser.java" private static byte[] init__warc_actions_0() { return new byte [] { 0, 1, 0, 1, 1, 1, 2, 1, 3, 1, 4, 1, - 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, - 13, 2, 0, 10, 2, 3, 0, 2, 4, 0, 2, 6, - 0, 3, 11, 12, 13 + 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 12, 2, + 3, 0, 2, 4, 0, 2, 6, 0, 3, 10, 11, 12 }; } @@ -362,9 +354,9 @@ private static short[] init__warc_key_offsets_0() 104, 106, 109, 111, 114, 116, 119, 121, 123, 125, 127, 129, 131, 133, 135, 137, 139, 141, 143, 145, 147, 148, 165, 167, 169, 172, 188, 205, 224, 228, 233, 236, 253, 269, 284, 302, - 309, 312, 316, 334, 351, 368, 386, 403, 412, 423, 435, 439, - 445, 448, 449, 452, 453, 456, 457, 460, 461, 477, 478, 494, - 500, 501, 519, 525, 531, 537, 537 + 309, 312, 316, 334, 351, 368, 386, 403, 412, 423, 435, 441, + 444, 445, 448, 449, 452, 453, 456, 457, 473, 474, 490, 496, + 497, 515, 521, 527, 533, 533 }; } @@ -410,15 +402,15 @@ private static char[] init__warc_trans_keys_0() 46, 48, 57, 65, 90, 94, 122, 9, 10, 32, 34, 92, 33, 126, 128, 255, 9, 34, 92, 32, 47, 48, 57, 58, 126, 128, 255, 9, 10, 34, 92, 32, 47, 48, 57, 58, - 126, 128, 255, 9, 10, 32, 59, 10, 32, 0, 191, 194, - 244, 32, 48, 57, 32, 46, 48, 57, 46, 46, 48, 57, - 46, 46, 48, 57, 46, 13, 33, 124, 126, 35, 39, 42, - 43, 45, 46, 48, 57, 65, 90, 94, 122, 10, 33, 58, - 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, - 94, 122, 9, 13, 32, 127, 0, 31, 10, 9, 13, 32, - 33, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, - 90, 94, 122, 9, 13, 32, 127, 0, 31, 9, 13, 32, - 127, 0, 31, 9, 13, 32, 127, 0, 31, 0 + 126, 128, 255, 10, 32, 0, 191, 194, 244, 32, 48, 57, + 32, 46, 48, 57, 46, 46, 48, 57, 46, 46, 48, 57, + 46, 13, 33, 124, 126, 35, 39, 42, 43, 45, 46, 48, + 57, 65, 90, 94, 122, 10, 33, 58, 124, 126, 35, 39, + 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 9, 13, + 32, 127, 0, 31, 10, 9, 13, 32, 33, 124, 126, 35, + 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 9, + 13, 32, 127, 0, 31, 9, 13, 32, 127, 0, 31, 9, + 13, 32, 127, 0, 31, 0 }; } @@ -433,9 +425,9 @@ private static byte[] init__warc_single_lengths_0() 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 5, 2, 0, 1, 6, 5, 7, 4, 3, 3, 5, 4, 3, 6, 3, - 3, 0, 6, 5, 5, 6, 5, 5, 3, 4, 4, 2, - 1, 1, 1, 1, 1, 1, 1, 1, 4, 1, 4, 4, - 1, 6, 4, 4, 4, 0, 0 + 3, 0, 6, 5, 5, 6, 5, 5, 3, 4, 2, 1, + 1, 1, 1, 1, 1, 1, 1, 4, 1, 4, 4, 1, + 6, 4, 4, 4, 0, 0 }; } @@ -450,9 +442,9 @@ private static byte[] init__warc_range_lengths_0() 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 6, 0, 1, 1, 5, 6, 6, 0, 1, 0, 6, 6, 6, 6, 2, - 0, 2, 6, 6, 6, 6, 6, 2, 4, 4, 0, 2, - 1, 0, 1, 0, 1, 0, 1, 0, 6, 0, 6, 1, - 0, 6, 1, 1, 1, 0, 0 + 0, 2, 6, 6, 6, 6, 6, 2, 4, 4, 2, 1, + 0, 1, 0, 1, 0, 1, 0, 6, 0, 6, 1, 0, + 6, 1, 1, 1, 0, 0 }; } @@ -468,8 +460,8 @@ private static short[] init__warc_index_offsets_0() 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 154, 157, 159, 162, 174, 186, 200, 205, 210, 214, 226, 237, 247, 260, 266, 270, 273, 286, 298, 310, 323, 335, 343, 351, 360, 365, - 370, 373, 375, 378, 380, 383, 385, 388, 390, 401, 403, 414, - 420, 422, 435, 441, 447, 453, 454 + 368, 370, 373, 375, 378, 380, 383, 385, 396, 398, 409, 415, + 417, 430, 436, 442, 448, 449 }; } @@ -491,32 +483,32 @@ private static byte[] init__warc_indicies_0() 1, 40, 41, 1, 42, 1, 43, 1, 44, 1, 45, 1, 46, 1, 47, 1, 48, 1, 49, 1, 50, 1, 51, 1, 52, 1, 53, 1, 54, 1, 55, 1, 56, 1, 1, 58, - 59, 59, 59, 59, 59, 59, 59, 59, 59, 57, 1, 60, - 57, 61, 1, 62, 61, 1, 1, 58, 59, 63, 59, 59, - 59, 59, 59, 59, 59, 57, 1, 60, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 57, 65, 1, 66, 64, 67, 64, - 64, 64, 64, 64, 64, 64, 64, 57, 65, 1, 68, 67, - 57, 69, 69, 70, 61, 1, 69, 69, 70, 1, 70, 70, - 71, 71, 71, 71, 71, 71, 71, 71, 71, 1, 71, 72, - 71, 71, 71, 71, 71, 71, 71, 71, 1, 74, 73, 73, - 73, 73, 73, 73, 73, 73, 1, 69, 66, 73, 70, 73, - 73, 73, 73, 73, 73, 73, 73, 1, 74, 75, 76, 74, - 74, 1, 69, 66, 70, 1, 74, 74, 1, 67, 1, 77, - 78, 78, 78, 78, 78, 78, 78, 78, 78, 57, 70, 70, - 71, 71, 71, 71, 71, 71, 79, 71, 71, 1, 62, 71, - 72, 71, 71, 71, 71, 71, 79, 71, 71, 1, 1, 60, - 78, 80, 78, 78, 78, 78, 78, 78, 78, 78, 57, 1, - 60, 81, 64, 64, 64, 64, 64, 64, 64, 64, 57, 81, - 1, 82, 83, 84, 81, 81, 57, 74, 75, 76, 74, 85, - 74, 74, 1, 74, 62, 75, 76, 74, 85, 74, 74, 1, - 65, 1, 66, 67, 57, 74, 82, 81, 81, 57, 40, 86, - 1, 40, 1, 37, 87, 1, 37, 1, 34, 88, 1, 34, - 1, 31, 89, 1, 31, 1, 90, 91, 91, 91, 91, 91, - 91, 91, 91, 91, 1, 92, 1, 91, 93, 91, 91, 91, - 91, 91, 91, 91, 91, 1, 94, 95, 94, 1, 1, 96, - 97, 1, 98, 99, 98, 100, 100, 100, 100, 100, 100, 100, - 100, 100, 1, 98, 101, 98, 1, 1, 102, 103, 104, 103, - 1, 1, 96, 105, 95, 105, 1, 1, 96, 1, 1, 0 + 59, 59, 59, 59, 59, 59, 59, 59, 59, 57, 1, 58, + 57, 60, 1, 61, 60, 1, 1, 58, 59, 62, 59, 59, + 59, 59, 59, 59, 59, 57, 1, 58, 63, 63, 63, 63, + 63, 63, 63, 63, 63, 57, 64, 1, 65, 63, 66, 63, + 63, 63, 63, 63, 63, 63, 63, 57, 64, 1, 65, 66, + 57, 67, 67, 68, 60, 1, 67, 67, 68, 1, 68, 68, + 69, 69, 69, 69, 69, 69, 69, 69, 69, 1, 69, 70, + 69, 69, 69, 69, 69, 69, 69, 69, 1, 72, 71, 71, + 71, 71, 71, 71, 71, 71, 1, 67, 65, 71, 68, 71, + 71, 71, 71, 71, 71, 71, 71, 1, 72, 73, 74, 72, + 72, 1, 67, 65, 68, 1, 72, 72, 1, 66, 1, 75, + 76, 76, 76, 76, 76, 76, 76, 76, 76, 57, 68, 68, + 69, 69, 69, 69, 69, 69, 77, 69, 69, 1, 61, 69, + 70, 69, 69, 69, 69, 69, 77, 69, 69, 1, 1, 58, + 76, 78, 76, 76, 76, 76, 76, 76, 76, 76, 57, 1, + 58, 79, 63, 63, 63, 63, 63, 63, 63, 63, 57, 79, + 1, 80, 64, 81, 79, 79, 57, 72, 73, 74, 72, 82, + 72, 72, 1, 72, 61, 73, 74, 72, 82, 72, 72, 1, + 72, 80, 79, 79, 57, 40, 83, 1, 40, 1, 37, 84, + 1, 37, 1, 34, 85, 1, 34, 1, 31, 86, 1, 31, + 1, 87, 88, 88, 88, 88, 88, 88, 88, 88, 88, 1, + 89, 1, 88, 90, 88, 88, 88, 88, 88, 88, 88, 88, + 1, 91, 92, 91, 1, 1, 93, 94, 1, 95, 96, 95, + 97, 97, 97, 97, 97, 97, 97, 97, 97, 1, 95, 98, + 95, 1, 1, 99, 100, 101, 100, 1, 1, 93, 102, 92, + 102, 1, 1, 93, 1, 1, 0 }; } @@ -527,14 +519,14 @@ private static byte[] init__warc_trans_targs_0() { return new byte [] { 2, 0, 20, 3, 4, 5, 6, 7, 8, 9, 10, 11, - 12, 13, 89, 14, 14, 15, 18, 16, 17, 12, 13, 15, - 18, 19, 15, 19, 21, 22, 23, 24, 78, 25, 26, 76, - 27, 28, 74, 29, 30, 72, 31, 32, 33, 34, 35, 36, + 12, 13, 88, 14, 14, 15, 18, 16, 17, 12, 13, 15, + 18, 19, 15, 19, 21, 22, 23, 24, 77, 25, 26, 75, + 27, 28, 73, 29, 30, 71, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 49, - 47, 48, 89, 50, 51, 52, 53, 62, 53, 54, 55, 56, - 57, 58, 59, 60, 61, 63, 65, 64, 66, 67, 68, 70, - 71, 69, 73, 75, 77, 79, 81, 82, 90, 83, 83, 84, - 87, 85, 86, 81, 82, 84, 87, 88, 84, 88 + 48, 88, 50, 51, 52, 53, 62, 54, 55, 56, 57, 58, + 59, 60, 61, 63, 65, 64, 66, 67, 68, 70, 69, 72, + 74, 76, 78, 80, 81, 89, 82, 82, 83, 86, 84, 85, + 80, 81, 83, 86, 87, 83, 87 }; } @@ -545,14 +537,14 @@ private static byte[] init__warc_trans_actions_0() { return new byte [] { 0, 0, 1, 0, 0, 0, 0, 3, 0, 5, 0, 0, - 0, 1, 23, 11, 0, 0, 1, 0, 0, 13, 34, 9, - 31, 28, 7, 1, 1, 15, 1, 1, 1, 1, 1, 1, + 0, 1, 21, 11, 0, 0, 1, 0, 0, 13, 29, 9, + 26, 23, 7, 1, 1, 15, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 17, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 19, 0, 21, 1, - 0, 1, 37, 1, 1, 1, 25, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 0, 1, 0, 11, 0, 0, - 1, 0, 0, 13, 34, 9, 31, 28, 7, 1 + 1, 1, 1, 1, 1, 1, 1, 1, 19, 0, 0, 0, + 1, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, + 1, 1, 1, 0, 1, 0, 11, 0, 0, 1, 0, 0, + 13, 29, 9, 26, 23, 7, 1 }; } @@ -560,12 +552,12 @@ private static final byte _warc_trans_actions[] = init__warc_trans_actions_0(); static final int warc_start = 1; -static final int warc_first_final = 89; +static final int warc_first_final = 88; static final int warc_error = 0; -static final int warc_en_warc_fields = 80; +static final int warc_en_warc_fields = 79; static final int warc_en_any_header = 1; -// line 262 "WarcParser.rl" +// line 257 "WarcParser.rl" } \ No newline at end of file diff --git a/test/org/netpreserve/jwarc/WarcParserTest.java b/test/org/netpreserve/jwarc/WarcParserTest.java index 6c9b431..4216591 100644 --- a/test/org/netpreserve/jwarc/WarcParserTest.java +++ b/test/org/netpreserve/jwarc/WarcParserTest.java @@ -11,11 +11,21 @@ import static org.junit.Assert.*; public class WarcParserTest { @Test public void testParsingArcWithBogusMime() { - String input = "http://example.com/ 1.2.3.4 20110104111607 @[=*�Content-Type] 494\n"; + WarcParser parser = parse("http://example.com/ 1.2.3.4 20110104111607 @[=*�Content-Type] 494\n"); + assertEquals(Optional.of("494"), parser.headers().sole("Content-Length")); + parser = parse("http://example.com/ 1.2.3.4 20110104111607 charset=foo 494\n"); + assertEquals(Optional.of("494"), parser.headers().sole("Content-Length")); + parser = parse("http://example.com/ 1.2.3.4 20110104111607 image(jpeg) 494\n"); + assertEquals(Optional.of("494"), parser.headers().sole("Content-Length")); + parser = parse("http://example.com/ 1.2.3.4 20110104111607 ERROR: 494\n"); + assertEquals(Optional.of("494"), parser.headers().sole("Content-Length")); + } + + private static WarcParser parse(String input) { WarcParser parser = new WarcParser(); parser.parse(ByteBuffer.wrap(input.getBytes(StandardCharsets.ISO_8859_1))); assertFalse(parser.isError()); assertTrue(parser.isFinished()); - assertEquals(Optional.of("494"), parser.headers().sole("Content-Length")); + return parser; } } \ No newline at end of file
https://github.com/iipc/jwarc.gitdiff --git a/src/org/netpreserve/jwarc/WarcParser.java b/src/org/netpreserve/jwarc/WarcParser.java
gitbug-java_data_iipc-jwarc.json_3
diff --git a/src/org/netpreserve/jwarc/cdx/CdxRequestEncoder.java b/src/org/netpreserve/jwarc/cdx/CdxRequestEncoder.java index c3d5220..db57870 100644 --- a/src/org/netpreserve/jwarc/cdx/CdxRequestEncoder.java +++ b/src/org/netpreserve/jwarc/cdx/CdxRequestEncoder.java @@ -56,13 +56,24 @@ public class CdxRequestEncoder { byte[] body = IOUtils.readNBytes(stream, limit); String decodedBody = String.valueOf(UTF_8.newDecoder().decode(ByteBuffer.wrap(body))); out.append('&'); - out.append(URIs.percentPlusDecode(decodedBody)); + percentEncodeNonPercent(URIs.percentPlusDecode(decodedBody), out); } catch (MalformedInputException e) { stream.reset(); encodeBinaryBody(stream, out); } } + private static void percentEncodeNonPercent(String s, StringBuilder out) { + for (byte rawByte : s.getBytes(UTF_8)) { + int b = rawByte & 0xff; + if (b == '#' || b <= 0x20 || b >= 0x7f) { + out.append('%').append(String.format("%02X", b)); + } else { + out.append((char) b); + } + } + } + private static void encodeJsonBody(InputStream stream, StringBuilder output, int maxLength, boolean binaryFallback) throws IOException { stream.mark(BUFFER_SIZE); JsonTokenizer tokenizer = new JsonTokenizer(new BufferedReader(new InputStreamReader(stream, UTF_8)), @@ -150,7 +161,7 @@ public class CdxRequestEncoder { public static String percentPlusEncode(String string) { StringBuilder output = new StringBuilder(); Formatter formatter = new Formatter(output); - byte[] bytes = string.getBytes(StandardCharsets.UTF_8); + byte[] bytes = string.getBytes(UTF_8); for (byte rawByte : bytes) { int b = rawByte & 0xff; if (percentPlusUnreserved.get(b)) { diff --git a/test/org/netpreserve/jwarc/cdx/CdxRequestEncoderTest.java b/test/org/netpreserve/jwarc/cdx/CdxRequestEncoderTest.java index d71a86c..a427bb5 100644 --- a/test/org/netpreserve/jwarc/cdx/CdxRequestEncoderTest.java +++ b/test/org/netpreserve/jwarc/cdx/CdxRequestEncoderTest.java @@ -29,6 +29,8 @@ public class CdxRequestEncoderTest { MediaType.WWW_FORM_URLENCODED, "foo=bar&dir=%2Fbaz"), new Case("__wb_method=POST&__wb_post_data=/w==", MediaType.WWW_FORM_URLENCODED, new byte[]{-1}), + new Case("__wb_method=POST&snowman=%E2%98%83", + MediaType.WWW_FORM_URLENCODED, "snowman=☃"), new Case("__wb_method=POST&a=b&a.2_=2&d=e", MediaType.JSON, "{\"a\": \"b\", \"c\": {\"a\": 2}, \"d\": \"e\"}"), new Case("__wb_method=POST",
https://github.com/iipc/jwarc.gitdiff --git a/src/org/netpreserve/jwarc/cdx/CdxRequestEncoder.java b/src/org/netpreserve/jwarc/cdx/CdxRequestEncoder.java
gitbug-java_data_iipc-jwarc.json_4
diff --git a/src/org/netpreserve/jwarc/MessageParser.java b/src/org/netpreserve/jwarc/MessageParser.java index 278511a..a8c4daa 100644 --- a/src/org/netpreserve/jwarc/MessageParser.java +++ b/src/org/netpreserve/jwarc/MessageParser.java @@ -6,8 +6,20 @@ package org.netpreserve.jwarc; import java.nio.ByteBuffer; +import java.util.function.Consumer; public class MessageParser { + private Consumer<String> warningHandler; + + protected void emitWarning(String message) { + if (warningHandler != null) { + warningHandler.accept(message); + } + } + + void onWarning(Consumer<String> warningHandler) { + this.warningHandler = warningHandler; + } protected static String getErrorContext(String input, int position, int length) { StringBuilder context = new StringBuilder(); diff --git a/src/org/netpreserve/jwarc/WarcParser.java b/src/org/netpreserve/jwarc/WarcParser.java index 753d66d..ed2c167 100644 --- a/src/org/netpreserve/jwarc/WarcParser.java +++ b/src/org/netpreserve/jwarc/WarcParser.java @@ -13,6 +13,7 @@ import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; import java.util.*; import static java.nio.charset.StandardCharsets.ISO_8859_1; @@ -20,7 +21,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.US_ASCII; -// line 142 "WarcParser.rl" +// line 156 "WarcParser.rl" /** @@ -83,7 +84,7 @@ public class WarcParser extends MessageParser { int pe = data.limit(); -// line 87 "WarcParser.java" +// line 88 "WarcParser.java" { int _klen; int _trans = 0; @@ -164,23 +165,23 @@ case 1: switch ( _warc_actions[_acts++] ) { case 0: -// line 26 "WarcParser.rl" +// line 27 "WarcParser.rl" { push(data.get(p)); } break; case 1: -// line 27 "WarcParser.rl" +// line 28 "WarcParser.rl" { major = major * 10 + data.get(p) - '0'; } break; case 2: -// line 28 "WarcParser.rl" +// line 29 "WarcParser.rl" { minor = minor * 10 + data.get(p) - '0'; } break; case 3: -// line 29 "WarcParser.rl" +// line 30 "WarcParser.rl" { endOfText = bufPos; } break; case 4: -// line 31 "WarcParser.rl" +// line 32 "WarcParser.rl" { if (bufPos > 0) { bufPos = endOfText; @@ -189,14 +190,14 @@ case 1: } break; case 5: -// line 38 "WarcParser.rl" +// line 39 "WarcParser.rl" { name = new String(buf, 0, bufPos, US_ASCII); bufPos = 0; } break; case 6: -// line 43 "WarcParser.rl" +// line 44 "WarcParser.rl" { String value = new String(buf, 0, endOfText, UTF_8); headerMap.computeIfAbsent(name, n -> new ArrayList<>()).add(value); @@ -205,7 +206,7 @@ case 1: } break; case 7: -// line 50 "WarcParser.rl" +// line 51 "WarcParser.rl" { String url = new String(buf, 0, bufPos, ISO_8859_1); if (url.startsWith("filedesc://")) { @@ -225,30 +226,42 @@ case 1: } break; case 8: -// line 68 "WarcParser.rl" +// line 69 "WarcParser.rl" { setHeader("WARC-IP-Address", new String(buf, 0, bufPos, US_ASCII)); bufPos = 0; } break; case 9: -// line 73 "WarcParser.rl" +// line 74 "WarcParser.rl" { String arcDate = new String(buf, 0, bufPos, US_ASCII); - Instant instant = LocalDateTime.parse(arcDate, arcTimeFormat).toInstant(ZoneOffset.UTC); - setHeader("WARC-Date", instant.toString()); + // Some WARC files have been seen in the wild with truncated dates + if (arcDate.length() < 14) { + emitWarning("ARC date too short (" + arcDate.length() + " digits)"); + arcDate = arcDate + "00000000000000".substring(arcDate.length()); + } else if (arcDate.length() > 14) { + emitWarning("ARC date too long (" + arcDate.length() + " digits)"); + arcDate = arcDate.substring(0, 14); + } + try { + Instant instant = LocalDateTime.parse(arcDate, arcTimeFormat).toInstant(ZoneOffset.UTC); + setHeader("WARC-Date", instant.toString()); + } catch (DateTimeParseException e) { + emitWarning("ARC date not parsable"); + } bufPos = 0; } break; case 10: -// line 80 "WarcParser.rl" +// line 93 "WarcParser.rl" { setHeader("Content-Length", new String(buf, 0, bufPos, US_ASCII)); bufPos = 0; } break; case 11: -// line 85 "WarcParser.rl" +// line 98 "WarcParser.rl" { protocol = "ARC"; major = 1; @@ -256,10 +269,10 @@ case 1: } break; case 12: -// line 140 "WarcParser.rl" +// line 154 "WarcParser.rl" { { p += 1; _goto_targ = 5; if (true) continue _goto;} } break; -// line 263 "WarcParser.java" +// line 276 "WarcParser.java" } } } @@ -279,7 +292,7 @@ case 5: break; } } -// line 204 "WarcParser.rl" +// line 218 "WarcParser.rl" position += p - data.position(); data.position(p); @@ -333,7 +346,7 @@ case 5: } -// line 337 "WarcParser.java" +// line 350 "WarcParser.java" private static byte[] init__warc_actions_0() { return new byte [] { @@ -352,11 +365,12 @@ private static short[] init__warc_key_offsets_0() 0, 0, 3, 4, 5, 6, 7, 9, 12, 14, 17, 18, 34, 35, 51, 57, 58, 76, 82, 88, 94, 97, 99, 101, 104, 106, 109, 111, 114, 116, 119, 121, 123, 125, 127, 129, - 131, 133, 135, 137, 139, 141, 143, 145, 147, 148, 165, 167, - 169, 172, 188, 205, 224, 228, 233, 236, 253, 269, 284, 302, - 309, 312, 316, 334, 351, 368, 386, 403, 412, 423, 435, 441, - 444, 445, 448, 449, 452, 453, 456, 457, 473, 474, 490, 496, - 497, 515, 521, 527, 533, 533 + 131, 133, 135, 138, 155, 157, 159, 162, 178, 195, 214, 218, + 223, 226, 243, 259, 274, 292, 299, 302, 306, 324, 341, 358, + 376, 393, 402, 413, 425, 431, 434, 437, 440, 443, 446, 449, + 452, 455, 458, 461, 464, 467, 470, 473, 476, 479, 482, 485, + 488, 489, 492, 493, 496, 497, 500, 501, 504, 505, 521, 522, + 538, 544, 545, 563, 569, 575, 581, 581 }; } @@ -377,32 +391,36 @@ private static char[] init__warc_trans_keys_0() 122, 10, 32, 48, 57, 46, 48, 57, 48, 57, 46, 48, 57, 48, 57, 46, 48, 57, 48, 57, 32, 48, 57, 48, 57, 48, 57, 48, 57, 48, 57, 48, 57, 48, 57, 48, - 57, 48, 57, 48, 57, 48, 57, 48, 57, 48, 57, 48, - 57, 48, 57, 32, 10, 32, 33, 124, 126, 35, 39, 42, - 43, 45, 46, 48, 57, 65, 90, 94, 122, 10, 32, 48, - 57, 10, 48, 57, 10, 32, 33, 47, 124, 126, 35, 39, - 42, 43, 45, 57, 65, 90, 94, 122, 10, 32, 33, 124, - 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, - 122, 9, 10, 32, 33, 59, 124, 126, 35, 39, 42, 43, - 45, 46, 48, 57, 65, 90, 94, 122, 9, 10, 32, 59, - 9, 32, 59, 48, 57, 9, 32, 59, 9, 32, 33, 124, - 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, - 122, 33, 61, 124, 126, 35, 39, 42, 43, 45, 46, 48, - 57, 65, 90, 94, 122, 34, 124, 126, 33, 39, 42, 43, - 45, 46, 48, 57, 65, 90, 94, 122, 9, 32, 33, 59, - 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, - 94, 122, 9, 34, 92, 32, 126, 128, 255, 9, 32, 59, - 0, 191, 194, 244, 9, 10, 32, 33, 124, 126, 35, 39, - 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 9, 32, + 57, 48, 57, 32, 48, 57, 10, 32, 33, 124, 126, 35, + 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 10, + 32, 48, 57, 10, 48, 57, 10, 32, 33, 47, 124, 126, + 35, 39, 42, 43, 45, 57, 65, 90, 94, 122, 10, 32, 33, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, - 90, 94, 122, 10, 33, 61, 124, 126, 35, 39, 42, 43, - 45, 46, 48, 57, 65, 90, 94, 122, 10, 32, 33, 61, - 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, - 94, 122, 10, 32, 34, 124, 126, 33, 39, 42, 43, 45, - 46, 48, 57, 65, 90, 94, 122, 9, 10, 32, 34, 92, - 33, 126, 128, 255, 9, 34, 92, 32, 47, 48, 57, 58, - 126, 128, 255, 9, 10, 34, 92, 32, 47, 48, 57, 58, - 126, 128, 255, 10, 32, 0, 191, 194, 244, 32, 48, 57, + 90, 94, 122, 9, 10, 32, 33, 59, 124, 126, 35, 39, + 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 9, 10, + 32, 59, 9, 32, 59, 48, 57, 9, 32, 59, 9, 32, + 33, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, + 90, 94, 122, 33, 61, 124, 126, 35, 39, 42, 43, 45, + 46, 48, 57, 65, 90, 94, 122, 34, 124, 126, 33, 39, + 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 9, 32, + 33, 59, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, + 65, 90, 94, 122, 9, 34, 92, 32, 126, 128, 255, 9, + 32, 59, 0, 191, 194, 244, 9, 10, 32, 33, 124, 126, + 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, + 9, 32, 33, 124, 126, 35, 39, 42, 43, 45, 46, 48, + 57, 65, 90, 94, 122, 10, 33, 61, 124, 126, 35, 39, + 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 10, 32, + 33, 61, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, + 65, 90, 94, 122, 10, 32, 34, 124, 126, 33, 39, 42, + 43, 45, 46, 48, 57, 65, 90, 94, 122, 9, 10, 32, + 34, 92, 33, 126, 128, 255, 9, 34, 92, 32, 47, 48, + 57, 58, 126, 128, 255, 9, 10, 34, 92, 32, 47, 48, + 57, 58, 126, 128, 255, 10, 32, 0, 191, 194, 244, 32, + 48, 57, 32, 48, 57, 32, 48, 57, 32, 48, 57, 32, + 48, 57, 32, 48, 57, 32, 48, 57, 32, 48, 57, 32, + 48, 57, 32, 48, 57, 32, 48, 57, 32, 48, 57, 32, + 48, 57, 32, 48, 57, 32, 48, 57, 32, 48, 57, 32, + 48, 57, 32, 48, 57, 32, 48, 57, 32, 32, 48, 57, 32, 46, 48, 57, 46, 46, 48, 57, 46, 46, 48, 57, 46, 13, 33, 124, 126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94, 122, 10, 33, 58, 124, 126, 35, 39, @@ -423,11 +441,12 @@ private static byte[] init__warc_single_lengths_0() 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 4, 1, 4, 4, 1, 6, 4, 4, 4, 1, 2, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1, 5, 2, 0, - 1, 6, 5, 7, 4, 3, 3, 5, 4, 3, 6, 3, - 3, 0, 6, 5, 5, 6, 5, 5, 3, 4, 2, 1, - 1, 1, 1, 1, 1, 1, 1, 4, 1, 4, 4, 1, - 6, 4, 4, 4, 0, 0 + 0, 0, 1, 5, 2, 0, 1, 6, 5, 7, 4, 3, + 3, 5, 4, 3, 6, 3, 3, 0, 6, 5, 5, 6, + 5, 5, 3, 4, 2, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 1, 4, + 4, 1, 6, 4, 4, 4, 0, 0 }; } @@ -440,11 +459,12 @@ private static byte[] init__warc_range_lengths_0() 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 6, 0, 6, 1, 0, 6, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 0, 6, 0, 1, - 1, 5, 6, 6, 0, 1, 0, 6, 6, 6, 6, 2, - 0, 2, 6, 6, 6, 6, 6, 2, 4, 4, 2, 1, - 0, 1, 0, 1, 0, 1, 0, 6, 0, 6, 1, 0, - 6, 1, 1, 1, 0, 0 + 1, 1, 1, 6, 0, 1, 1, 5, 6, 6, 0, 1, + 0, 6, 6, 6, 6, 2, 0, 2, 6, 6, 6, 6, + 6, 2, 4, 4, 2, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 1, 0, 1, 0, 1, 0, 1, 0, 6, 0, 6, + 1, 0, 6, 1, 1, 1, 0, 0 }; } @@ -457,11 +477,12 @@ private static short[] init__warc_index_offsets_0() 0, 0, 3, 5, 7, 9, 11, 13, 16, 18, 21, 23, 34, 36, 47, 53, 55, 68, 74, 80, 86, 89, 92, 94, 97, 99, 102, 104, 107, 109, 112, 114, 116, 118, 120, 122, - 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 154, 157, - 159, 162, 174, 186, 200, 205, 210, 214, 226, 237, 247, 260, - 266, 270, 273, 286, 298, 310, 323, 335, 343, 351, 360, 365, - 368, 370, 373, 375, 378, 380, 383, 385, 396, 398, 409, 415, - 417, 430, 436, 442, 448, 449 + 124, 126, 128, 131, 143, 146, 148, 151, 163, 175, 189, 194, + 199, 203, 215, 226, 236, 249, 255, 259, 262, 275, 287, 299, + 312, 324, 332, 340, 349, 354, 357, 360, 363, 366, 369, 372, + 375, 378, 381, 384, 387, 390, 393, 396, 399, 402, 405, 408, + 411, 413, 416, 418, 421, 423, 426, 428, 431, 433, 444, 446, + 457, 463, 465, 478, 484, 490, 496, 497 }; } @@ -481,34 +502,38 @@ private static byte[] init__warc_indicies_0() 1, 18, 28, 2, 1, 1, 29, 28, 30, 1, 31, 32, 1, 33, 1, 34, 35, 1, 36, 1, 37, 38, 1, 39, 1, 40, 41, 1, 42, 1, 43, 1, 44, 1, 45, 1, - 46, 1, 47, 1, 48, 1, 49, 1, 50, 1, 51, 1, - 52, 1, 53, 1, 54, 1, 55, 1, 56, 1, 1, 58, - 59, 59, 59, 59, 59, 59, 59, 59, 59, 57, 1, 58, - 57, 60, 1, 61, 60, 1, 1, 58, 59, 62, 59, 59, - 59, 59, 59, 59, 59, 57, 1, 58, 63, 63, 63, 63, - 63, 63, 63, 63, 63, 57, 64, 1, 65, 63, 66, 63, - 63, 63, 63, 63, 63, 63, 63, 57, 64, 1, 65, 66, - 57, 67, 67, 68, 60, 1, 67, 67, 68, 1, 68, 68, - 69, 69, 69, 69, 69, 69, 69, 69, 69, 1, 69, 70, - 69, 69, 69, 69, 69, 69, 69, 69, 1, 72, 71, 71, - 71, 71, 71, 71, 71, 71, 1, 67, 65, 71, 68, 71, - 71, 71, 71, 71, 71, 71, 71, 1, 72, 73, 74, 72, - 72, 1, 67, 65, 68, 1, 72, 72, 1, 66, 1, 75, - 76, 76, 76, 76, 76, 76, 76, 76, 76, 57, 68, 68, - 69, 69, 69, 69, 69, 69, 77, 69, 69, 1, 61, 69, - 70, 69, 69, 69, 69, 69, 77, 69, 69, 1, 1, 58, - 76, 78, 76, 76, 76, 76, 76, 76, 76, 76, 57, 1, - 58, 79, 63, 63, 63, 63, 63, 63, 63, 63, 57, 79, - 1, 80, 64, 81, 79, 79, 57, 72, 73, 74, 72, 82, - 72, 72, 1, 72, 61, 73, 74, 72, 82, 72, 72, 1, - 72, 80, 79, 79, 57, 40, 83, 1, 40, 1, 37, 84, - 1, 37, 1, 34, 85, 1, 34, 1, 31, 86, 1, 31, - 1, 87, 88, 88, 88, 88, 88, 88, 88, 88, 88, 1, - 89, 1, 88, 90, 88, 88, 88, 88, 88, 88, 88, 88, - 1, 91, 92, 91, 1, 1, 93, 94, 1, 95, 96, 95, - 97, 97, 97, 97, 97, 97, 97, 97, 97, 1, 95, 98, - 95, 1, 1, 99, 100, 101, 100, 1, 1, 93, 102, 92, - 102, 1, 1, 93, 1, 1, 0 + 46, 1, 47, 1, 48, 1, 49, 1, 50, 51, 1, 1, + 53, 54, 54, 54, 54, 54, 54, 54, 54, 54, 52, 1, + 53, 52, 55, 1, 56, 55, 1, 1, 53, 54, 57, 54, + 54, 54, 54, 54, 54, 54, 52, 1, 53, 58, 58, 58, + 58, 58, 58, 58, 58, 58, 52, 59, 1, 60, 58, 61, + 58, 58, 58, 58, 58, 58, 58, 58, 52, 59, 1, 60, + 61, 52, 62, 62, 63, 55, 1, 62, 62, 63, 1, 63, + 63, 64, 64, 64, 64, 64, 64, 64, 64, 64, 1, 64, + 65, 64, 64, 64, 64, 64, 64, 64, 64, 1, 67, 66, + 66, 66, 66, 66, 66, 66, 66, 1, 62, 60, 66, 63, + 66, 66, 66, 66, 66, 66, 66, 66, 1, 67, 68, 69, + 67, 67, 1, 62, 60, 63, 1, 67, 67, 1, 61, 1, + 70, 71, 71, 71, 71, 71, 71, 71, 71, 71, 52, 63, + 63, 64, 64, 64, 64, 64, 64, 72, 64, 64, 1, 56, + 64, 65, 64, 64, 64, 64, 64, 72, 64, 64, 1, 1, + 53, 71, 73, 71, 71, 71, 71, 71, 71, 71, 71, 52, + 1, 53, 74, 58, 58, 58, 58, 58, 58, 58, 58, 52, + 74, 1, 75, 59, 76, 74, 74, 52, 67, 68, 69, 67, + 77, 67, 67, 1, 67, 56, 68, 69, 67, 77, 67, 67, + 1, 67, 75, 74, 74, 52, 50, 78, 1, 50, 79, 1, + 50, 80, 1, 50, 81, 1, 50, 82, 1, 50, 83, 1, + 50, 84, 1, 50, 85, 1, 50, 86, 1, 50, 87, 1, + 50, 88, 1, 50, 89, 1, 50, 90, 1, 50, 91, 1, + 50, 92, 1, 50, 93, 1, 50, 94, 1, 50, 95, 1, + 50, 96, 1, 50, 1, 40, 97, 1, 40, 1, 37, 98, + 1, 37, 1, 34, 99, 1, 34, 1, 31, 100, 1, 31, + 1, 101, 102, 102, 102, 102, 102, 102, 102, 102, 102, 1, + 103, 1, 102, 104, 102, 102, 102, 102, 102, 102, 102, 102, + 1, 105, 106, 105, 1, 1, 107, 108, 1, 109, 110, 109, + 111, 111, 111, 111, 111, 111, 111, 111, 111, 1, 109, 112, + 109, 1, 1, 113, 114, 115, 114, 1, 1, 107, 116, 106, + 116, 1, 1, 107, 1, 1, 0 }; } @@ -519,14 +544,15 @@ private static byte[] init__warc_trans_targs_0() { return new byte [] { 2, 0, 20, 3, 4, 5, 6, 7, 8, 9, 10, 11, - 12, 13, 88, 14, 14, 15, 18, 16, 17, 12, 13, 15, - 18, 19, 15, 19, 21, 22, 23, 24, 77, 25, 26, 75, - 27, 28, 73, 29, 30, 71, 31, 32, 33, 34, 35, 36, - 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 49, - 48, 88, 50, 51, 52, 53, 62, 54, 55, 56, 57, 58, - 59, 60, 61, 63, 65, 64, 66, 67, 68, 70, 69, 72, - 74, 76, 78, 80, 81, 89, 82, 82, 83, 86, 84, 85, - 80, 81, 83, 86, 87, 83, 87 + 12, 13, 102, 14, 14, 15, 18, 16, 17, 12, 13, 15, + 18, 19, 15, 19, 21, 22, 23, 24, 91, 25, 26, 89, + 27, 28, 87, 29, 30, 85, 31, 32, 33, 34, 35, 36, + 37, 38, 39, 65, 40, 41, 43, 42, 102, 44, 45, 46, + 47, 56, 48, 49, 50, 51, 52, 53, 54, 55, 57, 59, + 58, 60, 61, 62, 64, 63, 66, 67, 68, 69, 70, 71, + 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, + 84, 86, 88, 90, 92, 94, 95, 103, 96, 96, 97, 100, + 98, 99, 94, 95, 97, 100, 101, 97, 101 }; } @@ -540,11 +566,12 @@ private static byte[] init__warc_trans_actions_0() 0, 1, 21, 11, 0, 0, 1, 0, 0, 13, 29, 9, 26, 23, 7, 1, 1, 15, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 17, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 19, 0, 0, 0, - 1, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, - 1, 1, 1, 0, 1, 0, 11, 0, 0, 1, 0, 0, - 13, 29, 9, 26, 23, 7, 1 + 1, 1, 19, 1, 0, 0, 0, 1, 32, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 0, 1, 0, 11, 0, 0, 1, + 0, 0, 13, 29, 9, 26, 23, 7, 1 }; } @@ -552,12 +579,12 @@ private static final byte _warc_trans_actions[] = init__warc_trans_actions_0(); static final int warc_start = 1; -static final int warc_first_final = 88; +static final int warc_first_final = 102; static final int warc_error = 0; -static final int warc_en_warc_fields = 79; +static final int warc_en_warc_fields = 93; static final int warc_en_any_header = 1; -// line 257 "WarcParser.rl" +// line 271 "WarcParser.rl" } \ No newline at end of file diff --git a/src/org/netpreserve/jwarc/WarcReader.java b/src/org/netpreserve/jwarc/WarcReader.java index 2b884b9..60254ef 100644 --- a/src/org/netpreserve/jwarc/WarcReader.java +++ b/src/org/netpreserve/jwarc/WarcReader.java @@ -363,6 +363,7 @@ public class WarcReader implements Iterable<WarcRecord>, Closeable { */ public void onWarning(Consumer<String> warningHandler) { this.warningHandler = warningHandler; + parser.onWarning(warningHandler); } /** diff --git a/src/org/netpreserve/jwarc/cdx/CdxWriter.java b/src/org/netpreserve/jwarc/cdx/CdxWriter.java index 6e319c3..741894f 100644 --- a/src/org/netpreserve/jwarc/cdx/CdxWriter.java +++ b/src/org/netpreserve/jwarc/cdx/CdxWriter.java @@ -100,6 +100,12 @@ public class CdxWriter implements Closeable { record = reader.next().orElse(null); long length = reader.position() - position; + // skip records without a date, this often occurs in old ARC files with a corrupt date field + if (!capture.headers().first("WARC-Date").isPresent()) { + emitWarning(filename, position, "Skipping record due to missing or invalid date"); + continue; + } + String encodedRequest = null; if (postAppend) { // check for a corresponding request record diff --git a/test/org/netpreserve/jwarc/WarcParserTest.java b/test/org/netpreserve/jwarc/WarcParserTest.java index 4216591..dec7381 100644 --- a/test/org/netpreserve/jwarc/WarcParserTest.java +++ b/test/org/netpreserve/jwarc/WarcParserTest.java @@ -21,6 +21,16 @@ public class WarcParserTest { assertEquals(Optional.of("494"), parser.headers().sole("Content-Length")); } + @Test + public void testParsingArcWithCorruptDates() { + WarcParser parser = parse("http://example.com/ 1.2.3.4 200012120739 text/html 42\n"); + assertEquals(Optional.of("2000-12-12T07:39:00Z"), parser.headers().first("WARC-Date")); + parser = parse("http://example.com/ 1.2.3.4 2000121207394211 text/html 1942\n"); + assertEquals(Optional.of("2000-12-12T07:39:42Z"), parser.headers().first("WARC-Date")); + parser = parse("http://example.com/ 1.2.3.4 99999999999999 text/html 1942\n"); + assertEquals(Optional.empty(), parser.headers().first("WARC-Date")); + } + private static WarcParser parse(String input) { WarcParser parser = new WarcParser(); parser.parse(ByteBuffer.wrap(input.getBytes(StandardCharsets.ISO_8859_1)));
https://github.com/iipc/jwarc.gitdiff --git a/src/org/netpreserve/jwarc/MessageParser.java b/src/org/netpreserve/jwarc/MessageParser.java
gitbug-java_data_adoble-adr-j.json_1
diff --git a/src/main/java/org/doble/commands/CommandADR.java b/src/main/java/org/doble/commands/CommandADR.java index 216e3db..6e545e8 100644 --- a/src/main/java/org/doble/commands/CommandADR.java +++ b/src/main/java/org/doble/commands/CommandADR.java @@ -19,7 +19,7 @@ import picocli.CommandLine.HelpCommand; @Command(name = "adr", description = "Creation and management of architectural decision records (ADRs)", - version = "2.1", + version = "3.2.1", exitCodeListHeading = "Exit Codes:%n", exitCodeList = { " 0:Successful program execution.", "64:Invalid input: an unknown option or invalid parameter was specified.", diff --git a/src/main/java/org/doble/commands/CommandNew.java b/src/main/java/org/doble/commands/CommandNew.java index ea37e42..cd2f34a 100644 --- a/src/main/java/org/doble/commands/CommandNew.java +++ b/src/main/java/org/doble/commands/CommandNew.java @@ -236,7 +236,7 @@ public class CommandNew implements Callable<Integer> { /** * Find the highest index of the ADRs in the adr directory by iterating - * through all the files + * through all the files that start with an adr index number (i.e. dddd where d is a digit) * * @return int The highest index found. If no files are found returns 0. */ @@ -248,19 +248,58 @@ public class CommandNew implements Callable<Integer> { Path adrPath = rootPath.resolve(docPath); try { - highestIndex = Files.list(adrPath).mapToInt(CommandNew::toInt).max(); + highestIndex = Files.list(adrPath).filter(CommandNew::wellFormedADR).mapToInt(CommandNew::toInt).max(); + } catch (IOException e) { throw new ADRException("FATAL: Unable to determine the indexes of the ADRs.", e); - } + } return (highestIndex.isPresent() ? highestIndex.getAsInt() : 0); } + // Convert a ADR file name to its id number + // Assumes that the ADR file name is well formed. private static int toInt(Path p) { String name = p.getFileName().toString(); - // Extract the first 4 characters - String id = name.substring(0, 4); - return new Integer(id); + // Extract the first 4 characters and creat an integer from them + String id = name.substring(0, ADR.MAX_ID_LENGTH); + return Integer.parseInt(id); + } + + /* + * A well formed ADR has the form: + * dddd-* + * where 'd' is a digit + * and * refers to any number of charaters. + */ + private static boolean wellFormedADR(Path p) { + + String name = p.getFileName().toString(); + + // Instead of using a regex do some simple, and fast, checks + + // Check that the file is longer than the id length and the '-' + if (name.length() < ADR.MAX_ID_LENGTH + 1) { + return false; + } + + // Check that the 5th character is a '-' + if (name.indexOf('-') != ADR.MAX_ID_LENGTH) return false; + + // Check that the first 4 characters are digits + boolean is_adr_with_index = name.chars().mapToObj(i -> (char)i).limit(ADR.MAX_ID_LENGTH).allMatch(c -> Character.isDigit(c)); + if (!is_adr_with_index) { + return false; + } + + + + // All checks passed + return true; + + } + + } diff --git a/src/main/java/org/doble/commands/CommandVersion.java b/src/main/java/org/doble/commands/CommandVersion.java index a15bd3e..164d270 100644 --- a/src/main/java/org/doble/commands/CommandVersion.java +++ b/src/main/java/org/doble/commands/CommandVersion.java @@ -28,7 +28,7 @@ public class CommandVersion implements Callable<Integer> { * Version numbers adhere to to Semantic Versioning: https://semver.org/spec/v2.0.0.html * * * *******************************************************************************************/ - private String version = "3.2.0"; // Minor release, backwards compatible + private String version = "3.2.1"; // Minor release, backwards compatible @ParentCommand diff --git a/src/test/java/org/doble/adr/CommandNewTest.java b/src/test/java/org/doble/adr/CommandNewTest.java index 794797d..5c6db46 100644 --- a/src/test/java/org/doble/adr/CommandNewTest.java +++ b/src/test/java/org/doble/adr/CommandNewTest.java @@ -124,6 +124,43 @@ public class CommandNewTest { assertTrue(actualFileNames.containsAll(expectedFileNames), "File(s) missing"); assertTrue(expectedFileNames.containsAll(actualFileNames), "Unexpected file(s) found"); } + + // Tests to check that issue 43 has been corrected + @Test + public void testOtherFilesInADRDirectory () throws Exception { + String adrTitle1 = "Test architecture decision 1"; + String adrTitle2 = "Test architecture decision 2"; + + String[] args = TestUtilities.argify("new " + adrTitle1); + + int exitCode = ADR.run(args, env); + assertEquals(0, exitCode); + + args = TestUtilities.argify("new " + adrTitle2); + + exitCode = ADR.run(args, env); + assertEquals(0, exitCode); + + + // Add a new file that does not follow the ADR naming convention. + Files.createFile(fileSystem.getPath(rootPathName, docsPath, "other_doc.md")); + + // Try and create a new ADR. It should work. + args = TestUtilities.argify("new " + "New decision"); + + exitCode = ADR.run(args, env); + assertEquals(0, exitCode); + + // Add a new directory to the adr directory + Files.createDirectory(fileSystem.getPath(rootPathName, docsPath, "images")); + + // Try and create a new ADR. It should work. + args = TestUtilities.argify("new " + "Another decision"); + + exitCode = ADR.run(args, env); + assertEquals(0, exitCode); + + } }
https://github.com/adoble/adr-j.gitdiff --git a/src/main/java/org/doble/commands/CommandADR.java b/src/main/java/org/doble/commands/CommandADR.java
gitbug-java_data_st-tu-dresden-salespoint.json_1
diff --git a/src/main/java/org/salespointframework/accountancy/PersistentAccountancy.java b/src/main/java/org/salespointframework/accountancy/PersistentAccountancy.java index 8b57faa..6f8cab1 100755 --- a/src/main/java/org/salespointframework/accountancy/PersistentAccountancy.java +++ b/src/main/java/org/salespointframework/accountancy/PersistentAccountancy.java @@ -45,6 +45,7 @@ import org.springframework.util.Assert; * @author Hannes Weisbach * @author Thomas Dedek * @author Oliver Gierke + * @author Rebecca Uecker */ @Service @Transactional @@ -62,6 +63,7 @@ class PersistentAccountancy implements Accountancy { public final <T extends AccountancyEntry> T add(T accountancyEntry) { Assert.notNull(accountancyEntry, "Accountancy entry must not be null!"); + Assert.isTrue(!repository.existsById(accountancyEntry.getId()), "Accountancy entry must not exist in repository!"); if (!accountancyEntry.hasDate()) { accountancyEntry.setDate(businessTime.getTime()); diff --git a/src/test/java/org/salespointframework/accountancy/AccountancyTests.java b/src/test/java/org/salespointframework/accountancy/AccountancyTests.java index 8f99bea..162af4f 100644 --- a/src/test/java/org/salespointframework/accountancy/AccountancyTests.java +++ b/src/test/java/org/salespointframework/accountancy/AccountancyTests.java @@ -15,6 +15,8 @@ */ package org.salespointframework.accountancy; +import static org.junit.jupiter.api.Assertions.assertThrows; + import java.time.LocalDateTime; import org.javamoney.moneta.Money; @@ -83,4 +85,11 @@ class AccountancyTests { System.out.println("All entries:"); accountancy.find(Interval.from(from).to(to)).forEach(System.out::println); } + + @Test + void addExistingEntry() { + var existingEntry = new AccountancyEntry(Money.of(1.00, Currencies.EURO)); + accountancy.add(existingEntry); + assertThrows(IllegalArgumentException.class, () -> accountancy.add(existingEntry), "Adding the same AccountancyEntry more than once should result in IllegalArgumentException!"); + } }
https://github.com/st-tu-dresden/salespoint.gitdiff --git a/src/main/java/org/salespointframework/accountancy/PersistentAccountancy.java b/src/main/java/org/salespointframework/accountancy/PersistentAccountancy.java
gitbug-java_data_TheAlgorithms-Java.json_1
diff --git a/src/main/java/com/thealgorithms/maths/FindMin.java b/src/main/java/com/thealgorithms/maths/FindMin.java index e3be09e..7764c1c 100644 --- a/src/main/java/com/thealgorithms/maths/FindMin.java +++ b/src/main/java/com/thealgorithms/maths/FindMin.java @@ -24,16 +24,20 @@ public class FindMin { } /** - * Find the minimum number of an array of numbers. + * @brief finds the minimum value stored in the input array * - * @param array the array contains element - * @return min value + * @param array the input array + * @exception IllegalArgumentException input array is empty + * @return the mimum value stored in the input array */ public static int findMin(int[] array) { - int min = array[0]; - for (int i = 1; i < array.length; ++i) { - if (array[i] < min) { - min = array[i]; + if (array.length == 0) { + throw new IllegalArgumentException("array must be non-empty."); + } + int min = Integer.MAX_VALUE; + for (final var value : array) { + if (value < min) { + min = value; } } return min; diff --git a/src/test/java/com/thealgorithms/maths/FindMinTest.java b/src/test/java/com/thealgorithms/maths/FindMinTest.java index 48fcb27..dc98354 100644 --- a/src/test/java/com/thealgorithms/maths/FindMinTest.java +++ b/src/test/java/com/thealgorithms/maths/FindMinTest.java @@ -1,6 +1,7 @@ package com.thealgorithms.maths; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import org.junit.jupiter.api.Test; @@ -23,4 +24,17 @@ public class FindMinTest { public void test2() { assertEquals(0, FindMin.findMin(new int[] { 0, 192, 384, 576 })); } + + @Test + public void test3() { + assertEquals(0, FindMin.findMin(new int[] { 10, 10, 0, 10 })); + } + + @Test + public void testFindMinThrowsExceptionForEmptyInput() { + assertThrows( + IllegalArgumentException.class, + () -> FindMin.findMin(new int[]{}) + ); + } }
https://github.com/TheAlgorithms/Java.gitdiff --git a/src/main/java/com/thealgorithms/maths/FindMin.java b/src/main/java/com/thealgorithms/maths/FindMin.java
gitbug-java_data_TheAlgorithms-Java.json_2
diff --git a/src/main/java/com/thealgorithms/maths/FindMax.java b/src/main/java/com/thealgorithms/maths/FindMax.java index a7be869..559424f 100644 --- a/src/main/java/com/thealgorithms/maths/FindMax.java +++ b/src/main/java/com/thealgorithms/maths/FindMax.java @@ -24,16 +24,20 @@ public class FindMax { } /** - * find max of array + * @brief finds the maximum value stored in the input array * - * @param array the array contains element - * @return max value of given array + * @param array the input array + * @exception IllegalArgumentException input array is empty + * @return the maximum value stored in the input array */ public static int findMax(int[] array) { - int max = array[0]; - for (int i = 1; i < array.length; ++i) { - if (array[i] > max) { - max = array[i]; + if (array.length == 0) { + throw new IllegalArgumentException("array must be non-empty."); + } + int max = Integer.MIN_VALUE; + for (final var value : array) { + if (value > max) { + max = value; } } return max; diff --git a/src/test/java/com/thealgorithms/maths/FindMaxTest.java b/src/test/java/com/thealgorithms/maths/FindMaxTest.java index 43daaea..a7a18fe 100644 --- a/src/test/java/com/thealgorithms/maths/FindMaxTest.java +++ b/src/test/java/com/thealgorithms/maths/FindMaxTest.java @@ -1,16 +1,41 @@ package com.thealgorithms.maths; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import org.junit.jupiter.api.Test; public class FindMaxTest { @Test - public void testFindMaxValue() { + public void testFindMax0() { assertEquals( 10, FindMax.findMax(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }) ); } + + @Test + public void testFindMax1() { + assertEquals( + 7, + FindMax.findMax(new int[] { 6, 3, 5, 1, 7, 4, 1 }) + ); + } + + @Test + public void testFindMax2() { + assertEquals( + 10, + FindMax.findMax(new int[] { 10, 0 }) + ); + } + + @Test + public void testFindMaxThrowsExceptionForEmptyInput() { + assertThrows( + IllegalArgumentException.class, + () -> FindMax.findMax(new int[]{}) + ); + } }
https://github.com/TheAlgorithms/Java.gitdiff --git a/src/main/java/com/thealgorithms/maths/FindMax.java b/src/main/java/com/thealgorithms/maths/FindMax.java
gitbug-java_data_TheAlgorithms-Java.json_3
diff --git a/src/main/java/com/thealgorithms/others/StackPostfixNotation.java b/src/main/java/com/thealgorithms/others/StackPostfixNotation.java index c6d395c..f859151 100644 --- a/src/main/java/com/thealgorithms/others/StackPostfixNotation.java +++ b/src/main/java/com/thealgorithms/others/StackPostfixNotation.java @@ -16,6 +16,9 @@ public final class StackPostfixNotation { if (tokens.hasNextInt()) { s.push(tokens.nextInt()); // If int then push to stack } else { // else pop top two values and perform the operation + if (s.size() < 2) { + throw new IllegalArgumentException("exp is not a proper postfix expression (too few arguments)."); + } int num2 = s.pop(); int num1 = s.pop(); String op = tokens.next(); diff --git a/src/test/java/com/thealgorithms/others/StackPostfixNotationTest.java b/src/test/java/com/thealgorithms/others/StackPostfixNotationTest.java index 4894b40..9256e2b 100644 --- a/src/test/java/com/thealgorithms/others/StackPostfixNotationTest.java +++ b/src/test/java/com/thealgorithms/others/StackPostfixNotationTest.java @@ -30,4 +30,14 @@ public class StackPostfixNotationTest { public void testIfEvaluateThrowsExceptionForInputWithUnknownOperation() { assertThrows(IllegalArgumentException.class, () -> StackPostfixNotation.postfixEvaluate("3 3 !")); } + + @Test + public void testIfEvaluateThrowsExceptionForInputWithTooFewArgsA() { + assertThrows(IllegalArgumentException.class, () -> StackPostfixNotation.postfixEvaluate("+")); + } + + @Test + public void testIfEvaluateThrowsExceptionForInputWithTooFewArgsB() { + assertThrows(IllegalArgumentException.class, () -> StackPostfixNotation.postfixEvaluate("2 +")); + } }
https://github.com/TheAlgorithms/Java.gitdiff --git a/src/main/java/com/thealgorithms/others/StackPostfixNotation.java b/src/main/java/com/thealgorithms/others/StackPostfixNotation.java
gitbug-java_data_TheAlgorithms-Java.json_4
diff --git a/src/main/java/com/thealgorithms/maths/Armstrong.java b/src/main/java/com/thealgorithms/maths/Armstrong.java index dda8288..526b31c 100644 --- a/src/main/java/com/thealgorithms/maths/Armstrong.java +++ b/src/main/java/com/thealgorithms/maths/Armstrong.java @@ -1,29 +1,36 @@ package com.thealgorithms.maths; /** - * An Armstrong number is equal to the sum of the cubes of its digits. For - * example, 370 is an Armstrong number because 3*3*3 + 7*7*7 + 0*0*0 = 370. An - * Armstrong number is often called Narcissistic number. + * This class checks whether a given number is an Armstrong number or not. + * An Armstrong number is a number that is equal to the sum of its own digits, + * each raised to the power of the number of digits. * - * @author Vivek + * For example, 370 is an Armstrong number because 3^3 + 7^3 + 0^3 = 370. + * 1634 is an Armstrong number because 1^4 + 6^4 + 3^4 + 4^4 = 1634. + * An Armstrong number is often called a Narcissistic number. + * + * @author satyabarghav */ public class Armstrong { /** - * Checks whether a given number is an armstrong number or not. + * Checks whether a given number is an Armstrong number or not. * - * @param number number to check - * @return {@code true} if given number is armstrong number, {@code false} - * otherwise + * @param number the number to check + * @return {@code true} if the given number is an Armstrong number, {@code false} otherwise */ public boolean isArmstrong(int number) { long sum = 0; - long number2 = number; - while (number2 > 0) { - long mod = number2 % 10; - sum += Math.pow(mod, 3); - number2 /= 10; + String temp = Integer.toString(number); // Convert the given number to a string + int power = temp.length(); // Extract the length of the number (number of digits) + long originalNumber = number; + + while (originalNumber > 0) { + long digit = originalNumber % 10; + sum += Math.pow(digit, power); // The digit raised to the power of the number of digits and added to the sum. + originalNumber /= 10; } + return sum == number; } } diff --git a/src/test/java/com/thealgorithms/maths/ArmstrongTest.java b/src/test/java/com/thealgorithms/maths/ArmstrongTest.java index 3b11b83..e5d0d9e 100644 --- a/src/test/java/com/thealgorithms/maths/ArmstrongTest.java +++ b/src/test/java/com/thealgorithms/maths/ArmstrongTest.java @@ -5,8 +5,8 @@ import static org.assertj.core.api.Assertions.assertThat; import org.junit.jupiter.api.Test; /** - * @author Vivek - * @since 15/03/22 + * @author satyabarghav + * @since 4/10/2023 */ class ArmstrongTest { @@ -17,7 +17,9 @@ class ArmstrongTest { assertThat(armstrong.isArmstrong(1)).isTrue(); assertThat(armstrong.isArmstrong(153)).isTrue(); assertThat(armstrong.isArmstrong(371)).isTrue(); - assertThat(armstrong.isArmstrong(1634)).isFalse(); + assertThat(armstrong.isArmstrong(1634)).isTrue(); assertThat(armstrong.isArmstrong(200)).isFalse(); + assertThat(armstrong.isArmstrong(548834)).isTrue(); + assertThat(armstrong.isArmstrong(9474)).isTrue(); } }
https://github.com/TheAlgorithms/Java.gitdiff --git a/src/main/java/com/thealgorithms/maths/Armstrong.java b/src/main/java/com/thealgorithms/maths/Armstrong.java
gitbug-java_data_spring-projects-spring-guice.json_1
diff --git a/src/main/java/org/springframework/guice/module/SpringModule.java b/src/main/java/org/springframework/guice/module/SpringModule.java index f373d59..d4d9f45 100644 --- a/src/main/java/org/springframework/guice/module/SpringModule.java +++ b/src/main/java/org/springframework/guice/module/SpringModule.java @@ -17,11 +17,9 @@ package org.springframework.guice.module; import java.lang.annotation.Annotation; -import java.lang.reflect.Method; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; @@ -58,11 +56,9 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.context.ApplicationContext; import org.springframework.core.ResolvableType; -import org.springframework.core.annotation.AnnotationUtils; +import org.springframework.core.annotation.MergedAnnotation; import org.springframework.core.type.MethodMetadata; -import org.springframework.core.type.StandardMethodMetadata; import org.springframework.util.ClassUtils; -import org.springframework.util.ReflectionUtils; /** * A Guice module that wraps a Spring {@link ApplicationContext}. @@ -137,7 +133,7 @@ public class SpringModule extends AbstractModule { if (definition.hasAttribute(SPRING_GUICE_SOURCE)) { continue; } - Optional<Annotation> bindingAnnotation = getAnnotationForBeanDefinition(definition, beanFactory); + Optional<Annotation> bindingAnnotation = getAnnotationForBeanDefinition(definition); if (definition.isAutowireCandidate() && definition.getRole() == AbstractBeanDefinition.ROLE_APPLICATION) { Type type; Class<?> clazz = beanFactory.getType(name); @@ -204,16 +200,15 @@ public class SpringModule extends AbstractModule { } } - private static Optional<Annotation> getAnnotationForBeanDefinition(BeanDefinition definition, - ConfigurableListableBeanFactory beanFactory) { - if (definition instanceof AnnotatedBeanDefinition - && ((AnnotatedBeanDefinition) definition).getFactoryMethodMetadata() != null) { - try { - Method factoryMethod = getFactoryMethod(beanFactory, definition); - return Arrays.stream(AnnotationUtils.getAnnotations(factoryMethod)) - .filter((a) -> Annotations.isBindingAnnotation(a.annotationType())).findFirst(); + private static Optional<Annotation> getAnnotationForBeanDefinition(BeanDefinition definition) { + if (definition instanceof AnnotatedBeanDefinition) { + MethodMetadata methodMetadata = ((AnnotatedBeanDefinition) definition).getFactoryMethodMetadata(); + if (methodMetadata != null) { + return methodMetadata.getAnnotations().stream().filter(MergedAnnotation::isDirectlyPresent) + .filter((mergedAnnotation) -> Annotations.isBindingAnnotation(mergedAnnotation.getType())) + .map(MergedAnnotation::synthesize).findFirst(); } - catch (Exception ex) { + else { return Optional.empty(); } } @@ -222,49 +217,6 @@ public class SpringModule extends AbstractModule { } } - private static Method getFactoryMethod(ConfigurableListableBeanFactory beanFactory, BeanDefinition definition) - throws Exception { - if (definition instanceof AnnotatedBeanDefinition) { - MethodMetadata factoryMethodMetadata = ((AnnotatedBeanDefinition) definition).getFactoryMethodMetadata(); - if (factoryMethodMetadata instanceof StandardMethodMetadata) { - return ((StandardMethodMetadata) factoryMethodMetadata).getIntrospectedMethod(); - } - } - BeanDefinition factoryDefinition = beanFactory.getBeanDefinition(definition.getFactoryBeanName()); - Class<?> factoryClass = ClassUtils.forName(factoryDefinition.getBeanClassName(), - beanFactory.getBeanClassLoader()); - return getFactoryMethod(definition, factoryClass); - } - - private static Method getFactoryMethod(BeanDefinition definition, Class<?> factoryClass) { - Method uniqueMethod = null; - for (Method candidate : getCandidateFactoryMethods(definition, factoryClass)) { - if (candidate.getName().equals(definition.getFactoryMethodName())) { - if (uniqueMethod == null) { - uniqueMethod = candidate; - } - else if (!hasMatchingParameterTypes(candidate, uniqueMethod)) { - return null; - } - } - } - return uniqueMethod; - } - - private static Method[] getCandidateFactoryMethods(BeanDefinition definition, Class<?> factoryClass) { - return shouldConsiderNonPublicMethods(definition) ? ReflectionUtils.getAllDeclaredMethods(factoryClass) - : factoryClass.getMethods(); - } - - private static boolean shouldConsiderNonPublicMethods(BeanDefinition definition) { - return (definition instanceof AbstractBeanDefinition) - && ((AbstractBeanDefinition) definition).isNonPublicAccessAllowed(); - } - - private static boolean hasMatchingParameterTypes(Method candidate, Method current) { - return Arrays.equals(candidate.getParameterTypes(), current.getParameterTypes()); - } - private static Set<Type> getAllSuperTypes(Type originalType, Class<?> clazz) { Set<Type> allInterfaces = new HashSet<>(); TypeLiteral<?> typeToken = TypeLiteral.get(originalType); @@ -420,34 +372,65 @@ public class SpringModule extends AbstractModule { String[] named = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.beanFactory, ResolvableType.forType(this.type)); - List<String> names = new ArrayList<String>(named.length); - if (named.length == 1) { - names.add(named[0]); + + List<String> candidateBeanNames = new ArrayList<>(named.length); + for (String name : named) { + BeanDefinition beanDefinition = this.beanFactory.getBeanDefinition(name); + // This is a Guice component bridged to spring + // If this were the target candidate, + // Guice would have injected it natively. + // Thus, it cannot be a candidate. + // GuiceFactoryBeans don't have 1-to-1 annotation mapping + // (since annotation attributes are ignored) + // Skip this candidate to avoid unexpected matches + // due to imprecise annotation mapping + if (!beanDefinition.hasAttribute(SPRING_GUICE_SOURCE)) { + candidateBeanNames.add(name); + } + } + + List<String> matchingBeanNames; + if (candidateBeanNames.size() == 1) { + matchingBeanNames = candidateBeanNames; } else { - for (String name : named) { - if (this.bindingAnnotation.isPresent()) { - if (this.bindingAnnotation.get() instanceof Named - || this.bindingAnnotation.get() instanceof javax.inject.Named) { - Optional<Annotation> annotation = SpringModule.getAnnotationForBeanDefinition( - this.beanFactory.getMergedBeanDefinition(name), this.beanFactory); - String boundName = getNameFromBindingAnnotation(this.bindingAnnotation); - if (annotation.isPresent() && this.bindingAnnotation.get().equals(annotation.get()) - || name.equals(boundName)) { - names.add(name); + matchingBeanNames = new ArrayList<String>(candidateBeanNames.size()); + for (String name : candidateBeanNames) { + // Make sure we don't add the same name twice using if/else + if (name.equals(this.name)) { + // Guice is injecting dependency of this type by bean name + matchingBeanNames.add(name); + } + else if (this.bindingAnnotation.isPresent()) { + String boundName = getNameFromBindingAnnotation(this.bindingAnnotation); + if (name.equals(boundName)) { + // Spring bean definition has a Named annotation that + // matches the name of the bean + // In such cases, we dedupe namedProvider (because it's + // Key equals typeProvider Key) + // Thus, this complementary check is required + // (because name field is null in typeProvider, + // and if check above wouldn't pass) + matchingBeanNames.add(name); + } + else { + Optional<Annotation> annotationOptional = SpringModule + .getAnnotationForBeanDefinition(this.beanFactory.getBeanDefinition(name)); + + if (annotationOptional.equals(this.bindingAnnotation)) { + // Found a bean with matching qualifier annotation + matchingBeanNames.add(name); } } } - if (name.equals(this.name)) { - names.add(name); - } } } - if (names.size() == 1) { - this.resultProvider = () -> this.beanFactory.getBean(names.get(0)); + if (matchingBeanNames.size() == 1) { + this.resultProvider = () -> this.beanFactory.getBean(matchingBeanNames.get(0)); } else { - for (String name : named) { + // Shouldn't we iterate over matching bean names here? + for (String name : candidateBeanNames) { if (this.beanFactory.getBeanDefinition(name).isPrimary()) { this.resultProvider = () -> this.beanFactory.getBean(name); break; diff --git a/src/test/java/org/springframework/guice/module/SpringModuleMetadataTests.java b/src/test/java/org/springframework/guice/module/SpringModuleMetadataTests.java index a091776..cf94bcd 100644 --- a/src/test/java/org/springframework/guice/module/SpringModuleMetadataTests.java +++ b/src/test/java/org/springframework/guice/module/SpringModuleMetadataTests.java @@ -16,7 +16,12 @@ package org.springframework.guice.module; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Qualifier; import com.google.inject.ConfigurationException; import com.google.inject.Guice; @@ -35,6 +40,7 @@ import org.springframework.core.type.filter.AnnotationTypeFilter; import org.springframework.core.type.filter.AssignableTypeFilter; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** @@ -69,6 +75,43 @@ public class SpringModuleMetadataTests { } @Test + public void threeServicesByQualifier() throws Exception { + Injector injector = createInjector(PrimaryConfig.class, QualifiedConfig.class); + + assertThat(injector.getInstance( + Key.get(Service.class, ServiceQualifierAnnotated.class.getAnnotation(ServiceQualifier.class)))) + .extracting("name").isEqualTo("emptyQualifierService"); + + assertThat(injector.getInstance( + Key.get(Service.class, EmptyServiceQualifierAnnotated.class.getAnnotation(ServiceQualifier.class)))) + .extracting("name").isEqualTo("emptyQualifierService"); + + assertThat(injector.getInstance( + Key.get(Service.class, MyServiceQualifierAnnotated.class.getAnnotation(ServiceQualifier.class)))) + .extracting("name").isEqualTo("myService"); + + assertThat(injector.getInstance(Key.get(Service.class, Names.named("namedService")))).extracting("name") + .isEqualTo("namedService"); + + assertThat(injector.getInstance(Key.get(Service.class, Names.named("namedServiceWithADifferentBeanName")))) + .extracting("name").isEqualTo("namedServiceWithADifferentBeanName"); + + assertThat(injector.getInstance(Service.class)).extracting("name").isEqualTo("primary"); + + // Test cases where we don't expect to find any bindings + assertThatCode(() -> injector.getInstance(Key.get(Service.class, Names.named("randomService")))) + .isInstanceOf(ConfigurationException.class); + + assertThatCode(() -> injector.getInstance( + Key.get(Service.class, NoServiceQualifierAnnotated.class.getAnnotation(ServiceQualifier.class)))) + .isInstanceOf(ConfigurationException.class); + + assertThatCode(() -> injector.getInstance(Key.get(Service.class, UnboundServiceQualifier.class))) + .isInstanceOf(ConfigurationException.class); + + } + + @Test public void includes() throws Exception { Injector injector = createInjector(TestConfig.class, MetadataIncludesConfig.class); assertThatExceptionOfType(ConfigurationException.class) @@ -92,10 +135,23 @@ public class SpringModuleMetadataTests { interface Service { + String getName(); + } protected static class MyService implements Service { + private final String name; + + protected MyService(String name) { + this.name = name; + } + + @Override + public String getName() { + return this.name; + } + } public static class Foo { @@ -135,7 +191,7 @@ public class SpringModuleMetadataTests { @Bean public Service service() { - return new MyService(); + return new MyService("service"); } } @@ -146,7 +202,7 @@ public class SpringModuleMetadataTests { @Bean @Primary public Service primary() { - return new MyService(); + return new MyService("primary"); } } @@ -156,7 +212,36 @@ public class SpringModuleMetadataTests { @Bean public Service more() { - return new MyService(); + return new MyService("more"); + } + + } + + @Configuration + public static class QualifiedConfig { + + @Bean + @Named("namedService") + public Service namedService() { + return new MyService("namedService"); + } + + @Bean + @Named("namedServiceWithADifferentBeanName") + public Service anotherNamedService() { + return new MyService("namedServiceWithADifferentBeanName"); + } + + @Bean + @ServiceQualifier + public Service emptyQualifierService() { + return new MyService("emptyQualifierService"); + } + + @Bean + @ServiceQualifier(type = "myService") + public Service myService(@Named("namedService") Service service) { + return new MyService("myService"); } } @@ -166,4 +251,38 @@ public class SpringModuleMetadataTests { } + @Qualifier + @Retention(RetentionPolicy.RUNTIME) + @interface ServiceQualifier { + + String type() default ""; + + } + + @Qualifier + @Retention(RetentionPolicy.RUNTIME) + @interface UnboundServiceQualifier { + + } + + @ServiceQualifier + interface ServiceQualifierAnnotated { + + } + + @ServiceQualifier(type = "") + interface EmptyServiceQualifierAnnotated { + + } + + @ServiceQualifier(type = "myService") + interface MyServiceQualifierAnnotated { + + } + + @ServiceQualifier(type = "noService") + interface NoServiceQualifierAnnotated { + + } + }
https://github.com/spring-projects/spring-guice.gitdiff --git a/src/main/java/org/springframework/guice/module/SpringModule.java b/src/main/java/org/springframework/guice/module/SpringModule.java
gitbug-java_data_jitterted-ensembler.json_1
diff --git a/src/main/java/com/jitterted/mobreg/domain/Ensemble.java b/src/main/java/com/jitterted/mobreg/domain/Ensemble.java index 4666f3a..c01327f 100644 --- a/src/main/java/com/jitterted/mobreg/domain/Ensemble.java +++ b/src/main/java/com/jitterted/mobreg/domain/Ensemble.java @@ -96,6 +96,7 @@ public class Ensemble { public void joinAsSpectator(MemberId memberId) { membersAsSpectators.add(memberId); membersWhoAccepted.remove(memberId); + membersWhoDeclined.remove(memberId); } private void requireHasSpace() { diff --git a/src/test/java/com/jitterted/mobreg/domain/EnsembleMembersTest.java b/src/test/java/com/jitterted/mobreg/domain/EnsembleMembersTest.java index 66d90e5..569a35a 100644 --- a/src/test/java/com/jitterted/mobreg/domain/EnsembleMembersTest.java +++ b/src/test/java/com/jitterted/mobreg/domain/EnsembleMembersTest.java @@ -46,6 +46,20 @@ public class EnsembleMembersTest { } @Test + void declinedMemberWhenJoinAsSpectatorRemovesFromDeclined() { + Ensemble ensemble = EnsembleFactory.withStartTimeNow(); + MemberId memberId = MemberId.of(123); + ensemble.declinedBy(memberId); + + ensemble.joinAsSpectator(memberId); + + assertThat(ensemble.declinedMembers()) + .isEmpty(); + assertThat(ensemble.spectators()) + .containsExactly(memberId); + } + + @Test public void acceptMemberByIdWithEnsembleRemembersTheMember() throws Exception { Ensemble ensemble = EnsembleFactory.withStartTimeNow(); MemberId memberId = MemberId.of(123);
https://github.com/jitterted/ensembler.gitdiff --git a/src/main/java/com/jitterted/mobreg/domain/Ensemble.java b/src/main/java/com/jitterted/mobreg/domain/Ensemble.java
gitbug-java_data_jitterted-ensembler.json_2
diff --git a/src/main/java/com/jitterted/mobreg/domain/Ensemble.java b/src/main/java/com/jitterted/mobreg/domain/Ensemble.java index c01327f..e6826ce 100644 --- a/src/main/java/com/jitterted/mobreg/domain/Ensemble.java +++ b/src/main/java/com/jitterted/mobreg/domain/Ensemble.java @@ -68,6 +68,7 @@ public class Ensemble { requireHasSpace(); membersWhoAccepted.add(memberId); membersWhoDeclined.remove(memberId); + membersAsSpectators.remove(memberId); } public Set<MemberId> spectators() { diff --git a/src/test/java/com/jitterted/mobreg/domain/EnsembleMembersTest.java b/src/test/java/com/jitterted/mobreg/domain/EnsembleMembersTest.java index 569a35a..cd27e0c 100644 --- a/src/test/java/com/jitterted/mobreg/domain/EnsembleMembersTest.java +++ b/src/test/java/com/jitterted/mobreg/domain/EnsembleMembersTest.java @@ -60,6 +60,20 @@ public class EnsembleMembersTest { } @Test + void spectatorWhenAcceptRemovesFromSpectators() { + Ensemble ensemble = EnsembleFactory.withStartTimeNow(); + MemberId memberId = MemberId.of(123); + ensemble.joinAsSpectator(memberId); + + ensemble.acceptedBy(memberId); + + assertThat(ensemble.spectators()) + .isEmpty(); + assertThat(ensemble.acceptedMembers()) + .containsExactly(memberId); + } + + @Test public void acceptMemberByIdWithEnsembleRemembersTheMember() throws Exception { Ensemble ensemble = EnsembleFactory.withStartTimeNow(); MemberId memberId = MemberId.of(123);
https://github.com/jitterted/ensembler.gitdiff --git a/src/main/java/com/jitterted/mobreg/domain/Ensemble.java b/src/main/java/com/jitterted/mobreg/domain/Ensemble.java
gitbug-java_data_jitterted-ensembler.json_3
diff --git a/src/main/java/com/jitterted/mobreg/domain/Ensemble.java b/src/main/java/com/jitterted/mobreg/domain/Ensemble.java index e6826ce..138e67a 100644 --- a/src/main/java/com/jitterted/mobreg/domain/Ensemble.java +++ b/src/main/java/com/jitterted/mobreg/domain/Ensemble.java @@ -75,13 +75,20 @@ public class Ensemble { return membersAsSpectators; } + public void joinAsSpectator(MemberId memberId) { + membersAsSpectators.add(memberId); + membersWhoAccepted.remove(memberId); + membersWhoDeclined.remove(memberId); + } + public boolean isDeclined(MemberId memberId) { return membersWhoDeclined.contains(memberId); } public void declinedBy(MemberId memberId) { - membersWhoAccepted.remove(memberId); membersWhoDeclined.add(memberId); + membersWhoAccepted.remove(memberId); + membersAsSpectators.remove(memberId); } public Stream<MemberId> declinedMembers() { @@ -94,12 +101,6 @@ public class Ensemble { } } - public void joinAsSpectator(MemberId memberId) { - membersAsSpectators.add(memberId); - membersWhoAccepted.remove(memberId); - membersWhoDeclined.remove(memberId); - } - private void requireHasSpace() { if (isFull()) { throw new EnsembleFullException("Currently have " + acceptedCount() + " registered."); diff --git a/src/test/java/com/jitterted/mobreg/domain/EnsembleMembersTest.java b/src/test/java/com/jitterted/mobreg/domain/EnsembleMembersTest.java index cd27e0c..5d7e7fb 100644 --- a/src/test/java/com/jitterted/mobreg/domain/EnsembleMembersTest.java +++ b/src/test/java/com/jitterted/mobreg/domain/EnsembleMembersTest.java @@ -74,6 +74,20 @@ public class EnsembleMembersTest { } @Test + void spectatorWhenDeclineRemovesFromSpectators() { + Ensemble ensemble = EnsembleFactory.withStartTimeNow(); + MemberId memberId = MemberId.of(123); + ensemble.joinAsSpectator(memberId); + + ensemble.declinedBy(memberId); + + assertThat(ensemble.spectators()) + .isEmpty(); + assertThat(ensemble.declinedMembers()) + .containsExactly(memberId); + } + + @Test public void acceptMemberByIdWithEnsembleRemembersTheMember() throws Exception { Ensemble ensemble = EnsembleFactory.withStartTimeNow(); MemberId memberId = MemberId.of(123); @@ -82,7 +96,6 @@ public class EnsembleMembersTest { assertThat(ensemble.acceptedCount()) .isEqualTo(1); - assertThat(ensemble.acceptedMembers()) .containsOnly(memberId); }
https://github.com/jitterted/ensembler.gitdiff --git a/src/main/java/com/jitterted/mobreg/domain/Ensemble.java b/src/main/java/com/jitterted/mobreg/domain/Ensemble.java
gitbug-java_data_jitterted-ensembler.json_4
diff --git a/src/main/java/com/jitterted/mobreg/adapter/in/web/member/EnsembleSummaryView.java b/src/main/java/com/jitterted/mobreg/adapter/in/web/member/EnsembleSummaryView.java index eba214e..2958d1a 100644 --- a/src/main/java/com/jitterted/mobreg/adapter/in/web/member/EnsembleSummaryView.java +++ b/src/main/java/com/jitterted/mobreg/adapter/in/web/member/EnsembleSummaryView.java @@ -32,12 +32,13 @@ public record EnsembleSummaryView(long id, public static EnsembleSummaryView toView(Ensemble ensemble, MemberId memberId, MemberService memberService) { List<MemberView> participantViews = transform(memberService, ensemble.acceptedMembers()); + List<MemberView> spectatorViews = transform(memberService, ensemble.spectators()); return new EnsembleSummaryView(ensemble.getId().id(), ensemble.name(), DateTimeFormatting.formatAsDateTimeForCommonIso8601(ensemble.startDateTime()), ensemble.acceptedCount(), participantViews, - participantViews, + spectatorViews, memberStatusToViewString(ensemble, memberId), ensemble.meetingLink().toString(), new GoogleCalendarLinkCreator().createFor(ensemble), diff --git a/src/test/java/com/jitterted/mobreg/adapter/in/web/member/EnsembleSummaryViewTest.java b/src/test/java/com/jitterted/mobreg/adapter/in/web/member/EnsembleSummaryViewTest.java index 9a0c677..6898889 100644 --- a/src/test/java/com/jitterted/mobreg/adapter/in/web/member/EnsembleSummaryViewTest.java +++ b/src/test/java/com/jitterted/mobreg/adapter/in/web/member/EnsembleSummaryViewTest.java @@ -69,6 +69,23 @@ class EnsembleSummaryViewTest { } @Test + public void spectatorIsInSpectatorList() throws Exception { + Ensemble ensemble = EnsembleFactory.withIdOf1AndOneDayInTheFuture(); + TestMemberBuilder memberBuilder = new TestMemberBuilder(); + Member member = memberBuilder + .withFirstName("name") + .withGithubUsername("participant_username") + .buildAndSave(); + ensemble.joinAsSpectator(member.getId()); + + EnsembleSummaryView ensembleSummaryView = EnsembleSummaryView + .toView(ensemble, member.getId(), memberBuilder.memberService()); + + assertThat(ensembleSummaryView.spectators()) + .containsExactly(MemberView.from(member)); + } + + @Test public void noRecordingEnsembleThenViewIncludesEmptyLink() throws Exception { Ensemble ensemble = EnsembleFactory.withIdOf1AndOneDayInTheFuture(); MemberService memberService = new DefaultMemberService(new InMemoryMemberRepository());
https://github.com/jitterted/ensembler.gitdiff --git a/src/main/java/com/jitterted/mobreg/adapter/in/web/member/EnsembleSummaryView.java b/src/main/java/com/jitterted/mobreg/adapter/in/web/member/EnsembleSummaryView.java
gitbug-java_data_jitterted-ensembler.json_5
diff --git a/src/main/java/com/jitterted/mobreg/adapter/in/web/member/EnsembleSummaryView.java b/src/main/java/com/jitterted/mobreg/adapter/in/web/member/EnsembleSummaryView.java index db88f8f..f569068 100644 --- a/src/main/java/com/jitterted/mobreg/adapter/in/web/member/EnsembleSummaryView.java +++ b/src/main/java/com/jitterted/mobreg/adapter/in/web/member/EnsembleSummaryView.java @@ -40,7 +40,8 @@ public record EnsembleSummaryView(long id, String memberStatusAsString = memberStatusToViewString(ensemble, memberId); MemberStatus memberStatusForEnsemble = ensemble.memberStatusFor(memberId); SpectatorAction spectatorAction = SpectatorAction.from(memberStatusForEnsemble); - ParticipantAction participantAction = ParticipantAction.from(memberStatusForEnsemble, ensemble.isFull()); + ParticipantAction participantAction = ParticipantAction.from(memberStatusForEnsemble, + ensemble.isFull() && memberStatusForEnsemble != MemberStatus.PARTICIPANT); return new EnsembleSummaryView( ensemble.getId().id(), @@ -118,11 +119,20 @@ record SpectatorAction(String actionUrl, String buttonText) { record ParticipantAction(String actionUrl, String buttonText, boolean disabled) { public static ParticipantAction from(MemberStatus memberStatus, boolean disabled) { + if (disabled && memberStatus == MemberStatus.PARTICIPANT) { + throw new IllegalStateException("Can't disable Participate Button if Member is a Participant"); + } + if (disabled) { + return new ParticipantAction( + "", + "Cannot Participate: Ensemble Full", + true); + } return switch (memberStatus) { case UNKNOWN, DECLINED -> new ParticipantAction( "/member/accept", "Participate in Rotation &#x2328;", - disabled); + false); case PARTICIPANT -> new ParticipantAction( "/member/decline", "Leave Rotation &#x1f44b;", @@ -130,7 +140,7 @@ record ParticipantAction(String actionUrl, String buttonText, boolean disabled) case SPECTATOR -> new ParticipantAction( "/member/accept", "Switch to Participant &#x2328;", - disabled); + false); }; } } diff --git a/src/test/java/com/jitterted/mobreg/adapter/in/web/member/EnsembleSummaryViewActionTest.java b/src/test/java/com/jitterted/mobreg/adapter/in/web/member/EnsembleSummaryViewActionTest.java index db72bd0..3265ca2 100644 --- a/src/test/java/com/jitterted/mobreg/adapter/in/web/member/EnsembleSummaryViewActionTest.java +++ b/src/test/java/com/jitterted/mobreg/adapter/in/web/member/EnsembleSummaryViewActionTest.java @@ -1,7 +1,6 @@ package com.jitterted.mobreg.adapter.in.web.member; import com.jitterted.mobreg.domain.MemberStatus; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -128,12 +127,17 @@ class EnsembleSummaryViewActionTest { } @Test // parameterize for Unknown/Declined/Spectator - @Disabled - void disabledWhenMemberIsNotParticipantAndRotationIsFull() { - ParticipantAction participantAction = ParticipantAction.from(MemberStatus.UNKNOWN, false); + void disabledTextShowsWhenButtonIsDisabled() { + ParticipantAction participantAction = ParticipantAction.from(MemberStatus.UNKNOWN, true); - assertThat(participantAction.disabled()) - .isTrue(); + ParticipantAction expectedParticipantAction = + new ParticipantAction( + "", + "Cannot Participate: Ensemble Full", + true); + + assertThat(participantAction) + .isEqualTo(expectedParticipantAction); } } diff --git a/src/test/java/com/jitterted/mobreg/adapter/in/web/member/EnsembleSummaryViewTest.java b/src/test/java/com/jitterted/mobreg/adapter/in/web/member/EnsembleSummaryViewTest.java index 449ad11..4f9dbbb 100644 --- a/src/test/java/com/jitterted/mobreg/adapter/in/web/member/EnsembleSummaryViewTest.java +++ b/src/test/java/com/jitterted/mobreg/adapter/in/web/member/EnsembleSummaryViewTest.java @@ -215,6 +215,7 @@ class EnsembleSummaryViewTest { assertThat(ensembleSummaryView.showActionButtons()) .isFalse(); } + }
https://github.com/jitterted/ensembler.gitdiff --git a/src/main/java/com/jitterted/mobreg/adapter/in/web/member/EnsembleSummaryView.java b/src/main/java/com/jitterted/mobreg/adapter/in/web/member/EnsembleSummaryView.java
gitbug-java_data_jitterted-ensembler.json_6
diff --git a/src/main/java/com/jitterted/mobreg/adapter/in/web/member/EnsembleSummaryView.java b/src/main/java/com/jitterted/mobreg/adapter/in/web/member/EnsembleSummaryView.java index a733adb..f2285ea 100644 --- a/src/main/java/com/jitterted/mobreg/adapter/in/web/member/EnsembleSummaryView.java +++ b/src/main/java/com/jitterted/mobreg/adapter/in/web/member/EnsembleSummaryView.java @@ -129,7 +129,7 @@ record ParticipantAction(String actionUrl, String buttonText, boolean disabled) false); // can always leave case SPECTATOR -> new ParticipantAction( "/member/accept", - "Switch to Participant &#x1f44b;", + "Switch to Participant &#x2328;", disabled); }; } diff --git a/src/test/java/com/jitterted/mobreg/adapter/in/web/member/EnsembleSummaryViewActionTest.java b/src/test/java/com/jitterted/mobreg/adapter/in/web/member/EnsembleSummaryViewActionTest.java index b0ff4e2..db72bd0 100644 --- a/src/test/java/com/jitterted/mobreg/adapter/in/web/member/EnsembleSummaryViewActionTest.java +++ b/src/test/java/com/jitterted/mobreg/adapter/in/web/member/EnsembleSummaryViewActionTest.java @@ -1,6 +1,7 @@ package com.jitterted.mobreg.adapter.in.web.member; import com.jitterted.mobreg.domain.MemberStatus; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -103,7 +104,7 @@ class EnsembleSummaryViewActionTest { ParticipantAction expectedParticipantAction = new ParticipantAction( "/member/decline", - "Leave Rotation &#x1f44b;", + "Leave Rotation &#x1f44b;", // hand wave symbol false); assertThat(participantAction) @@ -119,7 +120,7 @@ class EnsembleSummaryViewActionTest { ParticipantAction expectedParticipantAction = new ParticipantAction( "/member/accept", - "Switch to Participant &#x1f44b;", + "Switch to Participant &#x2328;", // keyboard symbol false); assertThat(participantAction) @@ -127,11 +128,12 @@ class EnsembleSummaryViewActionTest { } @Test // parameterize for Unknown/Declined/Spectator + @Disabled void disabledWhenMemberIsNotParticipantAndRotationIsFull() { -// ParticipantAction participantAction = ParticipantAction.disabled(""); -// -// assertThat(participantAction.disabled()) -// .isTrue(); + ParticipantAction participantAction = ParticipantAction.from(MemberStatus.UNKNOWN, false); + + assertThat(participantAction.disabled()) + .isTrue(); } }
https://github.com/jitterted/ensembler.gitdiff --git a/src/main/java/com/jitterted/mobreg/adapter/in/web/member/EnsembleSummaryView.java b/src/main/java/com/jitterted/mobreg/adapter/in/web/member/EnsembleSummaryView.java
gitbug-java_data_revelc-formatter-maven-plugin.json_1
diff --git a/src/main/java/net/revelc/code/formatter/css/CssFormatter.java b/src/main/java/net/revelc/code/formatter/css/CssFormatter.java index 1115835..f73773d 100644 --- a/src/main/java/net/revelc/code/formatter/css/CssFormatter.java +++ b/src/main/java/net/revelc/code/formatter/css/CssFormatter.java @@ -60,6 +60,12 @@ public class CssFormatter extends AbstractCacheableFormatter implements Formatte // Patch converted 'tab' back to '\9' for IE 7,8, and 9 hack. Cssparser switches it to 'tab'. formattedCode = formattedCode.replace("\t;", "\\9;"); + // Adding new line at end of file when needed + String[] lines = formattedCode.split(ending.getChars()); + if (!lines[lines.length - 1].equals(ending.getChars())) { + formattedCode = formattedCode + ending.getChars(); + } + if (code.equals(formattedCode)) { return null; } diff --git a/src/test/java/net/revelc/code/formatter/css/CssFormatterTest.java b/src/test/java/net/revelc/code/formatter/css/CssFormatterTest.java index 79f9b32..6c0d2c7 100644 --- a/src/test/java/net/revelc/code/formatter/css/CssFormatterTest.java +++ b/src/test/java/net/revelc/code/formatter/css/CssFormatterTest.java @@ -36,8 +36,8 @@ class CssFormatterTest extends AbstractFormatterTest { void testDoFormatFile() throws Exception { // FIXME Handle linux vs windows since this formatter does not accept line endings final var expectedHash = LineEnding.LF.isSystem() - ? "1af0032669532658f137ff80186df756abcfbccbe84e9663b54ef70be2c641f5af9e8c16ceeb3da7df9dc02599a3da0c0139a9397f93e383d6e8c6c50fd65c53" - : "684255d79eb28c6f4cfa340b6930fe1cfd9de16a1c6abf5f54e8f6837694b599101ef247ed00b8aea5460aa64cda60b418cebefd8ea28d5e747ed9cf4c3a9274"; + ? "6434062bd7499e707dea1ea17d301556712222b7671fae79ec20d906cda467a2b2210896a196dbaa9da7d221f04cab87a6b2e5538ca3c46fa7fdbedb46010a8c" + : "488b10041890a552141edb844a7d98f04ec2f30291a774dcb7f5fedcaad87dac85d3d9ed43b02f4d8d266e96549acd234038cff6e16b32a57034609f16330c8b"; final var lineEnding = LineEnding.LF.isSystem() ? LineEnding.LF : LineEnding.CRLF; this.twoPassTest(Collections.emptyMap(), new CssFormatter(), "someFile.css", expectedHash, lineEnding); }
https://github.com/revelc/formatter-maven-plugin.gitdiff --git a/src/main/java/net/revelc/code/formatter/css/CssFormatter.java b/src/main/java/net/revelc/code/formatter/css/CssFormatter.java
gitbug-java_data_klausbrunner-solarpositioning.json_1
diff --git a/src/main/java/net/e175/klaus/solarpositioning/Grena3.java b/src/main/java/net/e175/klaus/solarpositioning/Grena3.java index 40274ed..35a6a9c 100644 --- a/src/main/java/net/e175/klaus/solarpositioning/Grena3.java +++ b/src/main/java/net/e175/klaus/solarpositioning/Grena3.java @@ -38,6 +38,7 @@ public final class Grena3 { * @param deltaT Difference between earth rotation time and terrestrial time (or Universal Time and Terrestrial Time), * in seconds. See {@link JulianDate#JulianDate(ZonedDateTime, double)} and {@link DeltaT}. * @return Topocentric solar position (azimuth measured eastward from north) + * @throws IllegalArgumentException for nonsensical latitude/longitude * @see AzimuthZenithAngle */ public static AzimuthZenithAngle calculateSolarPosition(final ZonedDateTime date, final double latitude, @@ -63,11 +64,16 @@ public final class Grena3 { * correction of zenith angle. If unsure, 1000 is a reasonable default. * @param temperature Annual average local temperature, in degrees Celsius. Used for refraction correction of zenith angle. * @return Topocentric solar position (azimuth measured eastward from north) + * @throws IllegalArgumentException for nonsensical latitude/longitude * @see AzimuthZenithAngle */ public static AzimuthZenithAngle calculateSolarPosition(final ZonedDateTime date, final double latitude, final double longitude, final double deltaT, final double pressure, final double temperature) { + if(latitude < -90.0 || latitude > 90.0 || longitude < -180.0 || longitude > 180.0) { + throw new IllegalArgumentException("latitude/longitude out of range"); + } + final double t = calcT(date); final double tE = t + 1.1574e-5 * deltaT; final double omegaAtE = 0.0172019715 * tE; diff --git a/src/main/java/net/e175/klaus/solarpositioning/SPA.java b/src/main/java/net/e175/klaus/solarpositioning/SPA.java index 20d091e..fd7d6ff 100644 --- a/src/main/java/net/e175/klaus/solarpositioning/SPA.java +++ b/src/main/java/net/e175/klaus/solarpositioning/SPA.java @@ -43,11 +43,13 @@ public final class SPA { * correction of zenith angle. If unsure, 1000 is a reasonable default. * @param temperature Annual average local temperature, in degrees Celsius. Used for refraction correction of zenith angle. * @return Topocentric solar position (azimuth measured eastward from north) + * @throws IllegalArgumentException for nonsensical latitude/longitude * @see AzimuthZenithAngle */ public static AzimuthZenithAngle calculateSolarPosition(final ZonedDateTime date, final double latitude, final double longitude, final double elevation, final double deltaT, final double pressure, final double temperature) { + checkLatLonRange(latitude, longitude); // calculate Julian (ephemeris) date and millennium final JulianDate jd = new JulianDate(date, deltaT); @@ -124,6 +126,12 @@ public final class SPA { return calculateTopocentricSolarPosition(pressure, temperature, phi, deltaPrime, hPrime); } + private static void checkLatLonRange(double latitude, double longitude) { + if(latitude < -90.0 || latitude > 90.0 || longitude < -180.0 || longitude > 180.0) { + throw new IllegalArgumentException("latitude/longitude out of range"); + } + } + /** * Calculate topocentric solar position, i.e. the location of the sun on the sky for a certain point in time on a * certain point of the Earth's surface. @@ -141,6 +149,7 @@ public final class SPA { * @param deltaT Difference between earth rotation time and terrestrial time (or Universal Time and Terrestrial Time), * in seconds. See {@link JulianDate#JulianDate(ZonedDateTime, double)} and {@link DeltaT}. * @return Topocentric solar position (azimuth measured eastward from north) + * @throws IllegalArgumentException for nonsensical latitude/longitude * @see AzimuthZenithAngle */ public static AzimuthZenithAngle calculateSolarPosition(final ZonedDateTime date, final double latitude, @@ -168,11 +177,14 @@ public final class SPA { * @param longitude Observer's longitude, in degrees (negative west of Greenwich). * @param deltaT Difference between earth rotation time and terrestrial time (or Universal Time and Terrestrial Time), * in seconds. See {@link JulianDate#JulianDate(ZonedDateTime, double)} and {@link DeltaT}. + * @throws IllegalArgumentException for nonsensical latitude/longitude */ public static SunriseTransitSet calculateSunriseTransitSet(final ZonedDateTime day, final double latitude, final double longitude, final double deltaT) { + checkLatLonRange(latitude, longitude); + final ZonedDateTime dayStart = startOfDayUT(day); final JulianDate jd = new JulianDate(dayStart, 0); diff --git a/src/test/java/net/e175/klaus/solarpositioning/Grena3Test.java b/src/test/java/net/e175/klaus/solarpositioning/Grena3Test.java index 69b9e4e..00a0258 100644 --- a/src/test/java/net/e175/klaus/solarpositioning/Grena3Test.java +++ b/src/test/java/net/e175/klaus/solarpositioning/Grena3Test.java @@ -11,6 +11,7 @@ import java.time.ZonedDateTime; import static java.lang.Math.PI; import static java.lang.Math.toDegrees; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; class Grena3Test { @@ -67,6 +68,15 @@ class Grena3Test { assertEquals(result, result2); } + @Test + void testSillyLatLon() { + ZonedDateTime time = ZonedDateTime.of(2003, 10, 17, 12, 30, 30, 0, ZoneOffset.ofHours(-7)); + + assertThrows(IllegalArgumentException.class, () -> Grena3.calculateSolarPosition(time, 139.742476, -105.1786, 67, -2, 1000)); + + assertThrows(IllegalArgumentException.class, () -> Grena3.calculateSolarPosition(time, 39.742476, -205.1786, 67, -2, 1000)); + } + @ParameterizedTest @CsvFileSource(resources = "/azimuth_zenith/spa_reference_testdata.csv") void testBulkSpaReferenceValues(ZonedDateTime dateTime, double lat, double lon, double refAzimuth, double refZenith) { diff --git a/src/test/java/net/e175/klaus/solarpositioning/SPASunriseTransitSetTest.java b/src/test/java/net/e175/klaus/solarpositioning/SPASunriseTransitSetTest.java index b7e5b8f..f6b0f2a 100644 --- a/src/test/java/net/e175/klaus/solarpositioning/SPASunriseTransitSetTest.java +++ b/src/test/java/net/e175/klaus/solarpositioning/SPASunriseTransitSetTest.java @@ -15,6 +15,7 @@ import java.time.temporal.ChronoUnit; import static net.e175.klaus.solarpositioning.SunriseTransitSet.Type.*; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.within; +import static org.junit.jupiter.api.Assertions.assertThrows; class SPASunriseTransitSetTest { @@ -121,6 +122,15 @@ class SPASunriseTransitSetTest { compare(res, NORMAL, "2015-09-27T07:04:14+13:00", "2015-09-27T13:12:17+13:00", "2015-09-27T19:20:56+13:00", WITHIN_A_MINUTE); } + @Test + void testSillyLatLon() { + ZonedDateTime time = ZonedDateTime.of(2003, 10, 17, 12, 30, 30, 0, ZoneOffset.ofHours(-7)); + + assertThrows(IllegalArgumentException.class, () -> SPA.calculateSunriseTransitSet(time, 139.742476, -105.1786, 67)); + + assertThrows(IllegalArgumentException.class, () -> SPA.calculateSunriseTransitSet(time, 39.742476, -205.1786, 67)); + } + void compare(SunriseTransitSet res, ZonedDateTime baseDateTime, SunriseTransitSet.Type type, LocalTime sunrise, LocalTime transit, LocalTime sunset, TemporalUnitOffset tolerance) { compare(res, type, diff --git a/src/test/java/net/e175/klaus/solarpositioning/SPATest.java b/src/test/java/net/e175/klaus/solarpositioning/SPATest.java index 0b5ad5b..84574cd 100644 --- a/src/test/java/net/e175/klaus/solarpositioning/SPATest.java +++ b/src/test/java/net/e175/klaus/solarpositioning/SPATest.java @@ -8,6 +8,7 @@ import java.time.ZoneOffset; import java.time.ZonedDateTime; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; class SPATest { @@ -50,6 +51,15 @@ class SPATest { assertEquals(result, result2); } + @Test + void testSillyLatLon() { + ZonedDateTime time = ZonedDateTime.of(2003, 10, 17, 12, 30, 30, 0, ZoneOffset.ofHours(-7)); + + assertThrows(IllegalArgumentException.class, () -> SPA.calculateSolarPosition(time, 139.742476, -105.1786, 1830.14, 67, 820, 11)); + + assertThrows(IllegalArgumentException.class, () -> SPA.calculateSolarPosition(time, 39.742476, -205.1786, 1830.14, 67, 820, 11)); + } + @ParameterizedTest @CsvFileSource(resources = "/azimuth_zenith/spa_reference_testdata.csv") void testBulkSpaReferenceValues(ZonedDateTime dateTime, double lat, double lon, double refAzimuth, double refZenith) {
https://github.com/klausbrunner/solarpositioning.gitdiff --git a/src/main/java/net/e175/klaus/solarpositioning/Grena3.java b/src/main/java/net/e175/klaus/solarpositioning/Grena3.java
gitbug-java_data_klausbrunner-solarpositioning.json_2
diff --git a/src/main/java/net/e175/klaus/solarpositioning/DeltaT.java b/src/main/java/net/e175/klaus/solarpositioning/DeltaT.java index ff60ea7..5e382ac 100644 --- a/src/main/java/net/e175/klaus/solarpositioning/DeltaT.java +++ b/src/main/java/net/e175/klaus/solarpositioning/DeltaT.java @@ -13,7 +13,8 @@ public final class DeltaT { /** * Estimate Delta T for the given date. This is based on Espenak and Meeus, "Five Millennium Canon of - * Solar Eclipses: -1999 to +3000" (NASA/TP-2006-214141). + * Solar Eclipses: -1999 to +3000" (NASA/TP-2006-214141) and updated by Espenak in 2014 at + * <a href="https://www.eclipsewise.com/help/deltatpoly2014.html">Eclipsewise</a>. * * @param forDate date and time * @return estimated delta T value (seconds) @@ -63,14 +64,14 @@ public final class DeltaT { double t = year - 2000; deltaT = 63.86 + 0.3345 * t - 0.060374 * pow(t, 2) + 0.0017275 * pow(t, 3) + 0.000651814 * pow(t, 4) + 0.00002373599 * pow(t, 5); - } else if (year < 2050) { - double t = year - 2000; - deltaT = 62.92 + 0.32217 * t + 0.005589 * pow(t, 2); - } else if (year < 2150) { - deltaT = -20 + 32 * pow(((year - 1820) / 100), 2) - 0.5628 * (2150 - year); + } else if (year < 2015) { + double t = year - 2005; + deltaT = 64.69 + 0.2930 * t; + } else if (year <= 3000) { + double t = year - 2015; + deltaT = 67.62 + 0.3645 * t + 0.0039755 * pow(t, 2); } else { - double u = (year - 1820) / 100; - deltaT = -20 + 32 * pow(u, 2); + throw new IllegalArgumentException("no estimates possible for this time"); } return deltaT; diff --git a/src/test/java/net/e175/klaus/solarpositioning/DeltaTTest.java b/src/test/java/net/e175/klaus/solarpositioning/DeltaTTest.java index caacaf3..37f946b 100644 --- a/src/test/java/net/e175/klaus/solarpositioning/DeltaTTest.java +++ b/src/test/java/net/e175/klaus/solarpositioning/DeltaTTest.java @@ -26,28 +26,42 @@ class DeltaTTest { assertEquals(200, DeltaT.estimate(yearCal(1500)), 2); - assertEquals(7, DeltaT.estimate(yearCal(1850)), 1); + assertEquals(44, DeltaT.estimate(yearCal(1657)), 4); + + assertEquals(13.7, DeltaT.estimate(yearCal(1750)), 2); assertEquals(7, DeltaT.estimate(yearCal(1850)), 1); + assertEquals(1.04, DeltaT.estimate(yearCal(1870)), 1); + assertEquals(-3, DeltaT.estimate(yearCal(1900)), 1); + assertEquals(10.38, DeltaT.estimate(yearCal(1910)), 1); + + assertEquals(24.02, DeltaT.estimate(yearCal(1930)), 1); + assertEquals(29, DeltaT.estimate(yearCal(1950)), 1); } @Test void testObservedValues() { - assertEquals(31.1, DeltaT.estimate(yearCal(1955)), 1); + // values taken from https://maia.usno.navy.mil/products/deltaT + + assertEquals(45.4761, DeltaT.estimate(yearCal(1975)), 1); + + assertEquals(56.8553, DeltaT.estimate(yearCal(1990)), 1); + + assertEquals(63.8285, DeltaT.estimate(yearCal(2000)), 1); - assertEquals(45.5, DeltaT.estimate(yearCal(1975)), 1); + assertEquals(64.6876, DeltaT.estimate(yearCal(2005)), 1); - assertEquals(56.9, DeltaT.estimate(yearCal(1990)), 1); + assertEquals(66.0699, DeltaT.estimate(yearCal(2010)), 1); - assertEquals(63.8, DeltaT.estimate(yearCal(2000)), 1); + assertEquals(67.6439, DeltaT.estimate(yearCal(2015)), 1); - assertEquals(64.7, DeltaT.estimate(yearCal(2005)), 1); + assertEquals(69.3612, DeltaT.estimate(yearCal(2020)), 1); - assertEquals(68.0, DeltaT.estimate(yearCal(2015)), 2); + assertEquals(69.2945, DeltaT.estimate(yearCal(2022)), 2); } }
https://github.com/klausbrunner/solarpositioning.gitdiff --git a/src/main/java/net/e175/klaus/solarpositioning/DeltaT.java b/src/main/java/net/e175/klaus/solarpositioning/DeltaT.java
gitbug-java_data_davidmoten-word-wrap.json_1
diff --git a/src/main/java/org/davidmoten/text/utils/WordWrap.java b/src/main/java/org/davidmoten/text/utils/WordWrap.java index ceca282..b96ffee 100644 --- a/src/main/java/org/davidmoten/text/utils/WordWrap.java +++ b/src/main/java/org/davidmoten/text/utils/WordWrap.java @@ -229,6 +229,7 @@ public final class WordWrap { * @return this */ public Builder includeExtraWordChars(String includeWordChars) { + copyOnWriteDefaultWordCharset(); Set<Character> set = toSet(includeWordChars); this.extraWordChars.addAll(set); return this; @@ -242,12 +243,22 @@ public final class WordWrap { * @return this */ public Builder excludeExtraWordChars(String excludeWordChars) { + copyOnWriteDefaultWordCharset(); Set<Character> set = toSet(excludeWordChars); this.extraWordChars.removeAll(set); return this; } /** + * Create a copy of extraWordChars in case it refers to SPECIAL_WORD_CHARS_SET_DEFAULT. + */ + private void copyOnWriteDefaultWordCharset() { + if (this.extraWordChars == SPECIAL_WORD_CHARS_SET_DEFAULT) { + this.extraWordChars = new HashSet<>(SPECIAL_WORD_CHARS_SET_DEFAULT); + } + } + + /** * Sets if to break words using a hyphen character. If set to false then no * breaking character will be used. * diff --git a/src/test/java/org/davidmoten/text/utils/WordWrapTest.java b/src/test/java/org/davidmoten/text/utils/WordWrapTest.java index b9f1307..83fa05d 100644 --- a/src/test/java/org/davidmoten/text/utils/WordWrapTest.java +++ b/src/test/java/org/davidmoten/text/utils/WordWrapTest.java @@ -427,6 +427,13 @@ public class WordWrapTest { public void testNumbersWrapByDefault() { assertEquals("hello 12\n3", WordWrap.from("hello 123").breakWords(false).maxWidth(8).wrap()); } + + @Test + public void testStatelessness() { + assertEquals("hello super-\ncool", WordWrap.from("hello super-cool").breakWords(false).maxWidth(12).wrap()); + assertEquals("hello\nsuper-cool", WordWrap.from("hello super-cool").breakWords(false).maxWidth(12).includeExtraWordChars("-").wrap()); + assertEquals("hello super-\ncool", WordWrap.from("hello super-cool").breakWords(false).maxWidth(12).wrap()); + } //////////////////////////////////////////// // Novel wrapping tests
https://github.com/davidmoten/word-wrap.gitdiff --git a/src/main/java/org/davidmoten/text/utils/WordWrap.java b/src/main/java/org/davidmoten/text/utils/WordWrap.java
gitbug-java_data_retel-io-ari-proxy.json_1
diff --git a/src/main/java/io/retel/ariproxy/boundary/commandsandresponses/AriCommandResponseProcessing.java b/src/main/java/io/retel/ariproxy/boundary/commandsandresponses/AriCommandResponseProcessing.java index a2fc156..a247ce9 100644 --- a/src/main/java/io/retel/ariproxy/boundary/commandsandresponses/AriCommandResponseProcessing.java +++ b/src/main/java/io/retel/ariproxy/boundary/commandsandresponses/AriCommandResponseProcessing.java @@ -17,7 +17,8 @@ public class AriCommandResponseProcessing { final String callContext, final AriCommand ariCommand) { - if (!ariCommand.extractCommandType().isCreationCommand()) { + if (!(ariCommand.extractCommandType().isCreationCommand() + && "POST".equals(ariCommand.getMethod()))) { return Try.success(Done.done()); } diff --git a/src/test/java/io/retel/ariproxy/boundary/commandsandresponses/AriCommandResponseProcessingTest.java b/src/test/java/io/retel/ariproxy/boundary/commandsandresponses/AriCommandResponseProcessingTest.java index a2adf8b..9d7e8d4 100644 --- a/src/test/java/io/retel/ariproxy/boundary/commandsandresponses/AriCommandResponseProcessingTest.java +++ b/src/test/java/io/retel/ariproxy/boundary/commandsandresponses/AriCommandResponseProcessingTest.java @@ -54,7 +54,7 @@ class AriCommandResponseProcessingTest { AriCommandResponseProcessing.registerCallContext( callContextProvider.ref(), CALL_CONTEXT, - new AriCommand(null, "/channels/CHANNEL_ID/play/PLAYBACK_ID", null)); + new AriCommand("POST", "/channels/CHANNEL_ID/play/PLAYBACK_ID", null)); assertTrue(result.isSuccess()); final RegisterCallContext registerCallContext = @@ -64,13 +64,28 @@ class AriCommandResponseProcessingTest { } @Test + void doesNotTryToRegisterACallContextForDeleteRequests() { + final TestableCallContextProvider callContextProvider = + new TestableCallContextProvider(testKit); + + final Try<Done> result = + AriCommandResponseProcessing.registerCallContext( + callContextProvider.ref(), + CALL_CONTEXT, + new AriCommand("DELETE", "/channels/CHANNEL_ID", null)); + + assertTrue(result.isSuccess()); + callContextProvider.probe().expectNoMessage(); + } + + @Test void registerCallContextThrowsARuntimeExceptionIfTheAriCommandIsMalformed() { final TestProbe<CallContextProviderMessage> callContextProviderProbe = testKit.createTestProbe(CallContextProviderMessage.class); final Try<Done> result = AriCommandResponseProcessing.registerCallContext( - callContextProviderProbe.ref(), null, new AriCommand(null, "/channels", null)); + callContextProviderProbe.ref(), null, new AriCommand("POST", "/channels", null)); assertTrue(result.isFailure()); }
https://github.com/retel-io/ari-proxy.gitdiff --git a/src/main/java/io/retel/ariproxy/boundary/commandsandresponses/AriCommandResponseProcessing.java b/src/main/java/io/retel/ariproxy/boundary/commandsandresponses/AriCommandResponseProcessing.java
gitbug-java_data_jhy-jsoup.json_1
diff --git a/src/main/java/org/jsoup/nodes/TextNode.java b/src/main/java/org/jsoup/nodes/TextNode.java index 4dbd116..ecb39aa 100644 --- a/src/main/java/org/jsoup/nodes/TextNode.java +++ b/src/main/java/org/jsoup/nodes/TextNode.java @@ -93,13 +93,18 @@ public class TextNode extends LeafNode { trimTrailing = nextSibling() == null && parent != null && parent.tag().isBlock(); // if this text is just whitespace, and the next node will cause an indent, skip this text: - Node next = this.nextSibling(); + Node next = nextSibling(); + boolean isBlank = isBlank(); boolean couldSkip = (next instanceof Element && ((Element) next).shouldIndent(out)) // next will indent || (next instanceof TextNode && (((TextNode) next).isBlank())); // next is blank text, from re-parenting - if (couldSkip && isBlank()) return; - - if ((siblingIndex == 0 && parent != null && parent.tag().formatAsBlock() && !isBlank()) || - (out.outline() && siblingNodes().size() > 0 && !isBlank())) + if (couldSkip && isBlank) return; + + Node prev = previousSibling(); + if ( + (siblingIndex == 0 && parent != null && parent.tag().formatAsBlock() && !isBlank) || + (out.outline() && siblingNodes().size() > 0 && !isBlank) || + (siblingIndex > 0 && prev instanceof Element && ((Element) prev).normalName().equals("br")) // special case wrap on inline <br> - doesn't make sense as a block tag + ) indent(accum, depth, out); } diff --git a/src/test/java/org/jsoup/nodes/ElementTest.java b/src/test/java/org/jsoup/nodes/ElementTest.java index 0f51dc3..a0551f0 100644 --- a/src/test/java/org/jsoup/nodes/ElementTest.java +++ b/src/test/java/org/jsoup/nodes/ElementTest.java @@ -2213,6 +2213,7 @@ public class ElementTest { // testcase for https://github.com/jhy/jsoup/issues/1437 String html = "<p>Hello<br>World</p>"; Document doc = Jsoup.parse(html); + doc.outputSettings().prettyPrint(false); // otherwise html serializes as Hello<br>\n World. Element p = doc.select("p").first(); assertNotNull(p); assertEquals(html, p.outerHtml()); @@ -2220,6 +2221,13 @@ public class ElementTest { assertEquals("Hello\nWorld", p.wholeText()); } + @Test void wrapTextAfterBr() { + // https://github.com/jhy/jsoup/issues/1858 + String html = "<p>Hello<br>there<br>now.</p>"; + Document doc = Jsoup.parse(html); + assertEquals("<p>Hello<br>\n there<br>\n now.</p>", doc.body().html()); + } + @Test void preformatFlowsToChildTextNodes() { // https://github.com/jhy/jsoup/issues/1776 String html = "<div><pre>One\n<span>\nTwo</span>\n <span> \nThree</span>\n <span>Four <span>Five</span>\n Six\n</pre>"; diff --git a/src/test/java/org/jsoup/parser/HtmlParserTest.java b/src/test/java/org/jsoup/parser/HtmlParserTest.java index 5601d3a..eba7744 100644 --- a/src/test/java/org/jsoup/parser/HtmlParserTest.java +++ b/src/test/java/org/jsoup/parser/HtmlParserTest.java @@ -1192,7 +1192,7 @@ public class HtmlParserTest { assertTrue(Jsoup.isValid(html, Safelist.basic())); String clean = Jsoup.clean(html, Safelist.basic()); - assertEquals("<p>test<br>test<br></p>", clean); + assertEquals("<p>test<br>\n test<br></p>", clean); } @Test public void selfClosingOnNonvoidIsError() { diff --git a/src/test/java/org/jsoup/parser/XmlTreeBuilderTest.java b/src/test/java/org/jsoup/parser/XmlTreeBuilderTest.java index 98196a0..227dd09 100644 --- a/src/test/java/org/jsoup/parser/XmlTreeBuilderTest.java +++ b/src/test/java/org/jsoup/parser/XmlTreeBuilderTest.java @@ -94,7 +94,7 @@ public class XmlTreeBuilderTest { public void testDoesNotForceSelfClosingKnownTags() { // html will force "<br>one</br>" to logically "<br />One<br />". XML should be stay "<br>one</br> -- don't recognise tag. Document htmlDoc = Jsoup.parse("<br>one</br>"); - assertEquals("<br>one<br>", htmlDoc.body().html()); + assertEquals("<br>\none<br>", htmlDoc.body().html()); Document xmlDoc = Jsoup.parse("<br>one</br>", "", Parser.xmlParser()); assertEquals("<br>one</br>", xmlDoc.html()); diff --git a/src/test/java/org/jsoup/select/SelectorTest.java b/src/test/java/org/jsoup/select/SelectorTest.java index b3780ac..fd74487 100644 --- a/src/test/java/org/jsoup/select/SelectorTest.java +++ b/src/test/java/org/jsoup/select/SelectorTest.java @@ -2,6 +2,7 @@ package org.jsoup.select; import org.jsoup.Jsoup; import org.jsoup.MultiLocaleExtension.MultiLocaleTest; +import org.jsoup.TextUtil; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.parser.Parser; @@ -907,6 +908,7 @@ public class SelectorTest { @Test public void matchText() { String html = "<p>One<br>Two</p>"; Document doc = Jsoup.parse(html); + doc.outputSettings().prettyPrint(false); String origHtml = doc.html(); Elements one = doc.select("p:matchText:first-child");
https://github.com/jhy/jsoup.gitdiff --git a/src/main/java/org/jsoup/nodes/TextNode.java b/src/main/java/org/jsoup/nodes/TextNode.java
gitbug-java_data_jhy-jsoup.json_2
diff --git a/src/main/java/org/jsoup/nodes/TextNode.java b/src/main/java/org/jsoup/nodes/TextNode.java index ecb39aa..6d8ab63 100644 --- a/src/main/java/org/jsoup/nodes/TextNode.java +++ b/src/main/java/org/jsoup/nodes/TextNode.java @@ -84,13 +84,12 @@ public class TextNode extends LeafNode { final boolean prettyPrint = out.prettyPrint(); final Element parent = parentNode instanceof Element ? ((Element) parentNode) : null; final boolean normaliseWhite = prettyPrint && !Element.preserveWhitespace(parentNode); + final boolean trimLikeBlock = parent != null && (parent.tag().isBlock() || parent.tag().formatAsBlock()); + boolean trimLeading = false, trimTrailing = false; - boolean trimLeading = false; - boolean trimTrailing = false; if (normaliseWhite) { - trimLeading = (siblingIndex == 0 && parent != null && parent.tag().isBlock()) || - parentNode instanceof Document; - trimTrailing = nextSibling() == null && parent != null && parent.tag().isBlock(); + trimLeading = (trimLikeBlock && siblingIndex == 0) || parentNode instanceof Document; + trimTrailing = trimLikeBlock && nextSibling() == null; // if this text is just whitespace, and the next node will cause an indent, skip this text: Node next = nextSibling(); diff --git a/src/test/java/org/jsoup/nodes/ElementTest.java b/src/test/java/org/jsoup/nodes/ElementTest.java index a0551f0..5c8b0b7 100644 --- a/src/test/java/org/jsoup/nodes/ElementTest.java +++ b/src/test/java/org/jsoup/nodes/ElementTest.java @@ -2369,4 +2369,15 @@ public class ElementTest { Document doc = Jsoup.parse(html); assertEquals("<div><a>Text</a>\n</div>", doc.body().html()); } + + @Test void noDanglingSpaceAfterCustomElement() { + // https://github.com/jhy/jsoup/issues/1852 + String html = "<bar><p/>\n</bar>"; + Document doc = Jsoup.parse(html); + assertEquals("<bar>\n <p></p>\n</bar>", doc.body().html()); + + html = "<foo>\n <bar />\n</foo>"; + doc = Jsoup.parse(html); + assertEquals("<foo>\n <bar />\n</foo>", doc.body().html()); + } } \ No newline at end of file
https://github.com/jhy/jsoup.gitdiff --git a/src/main/java/org/jsoup/nodes/TextNode.java b/src/main/java/org/jsoup/nodes/TextNode.java
gitbug-java_data_jhy-jsoup.json_3
diff --git a/src/main/java/org/jsoup/helper/HttpConnection.java b/src/main/java/org/jsoup/helper/HttpConnection.java index 6b856fe..cb45448 100644 --- a/src/main/java/org/jsoup/helper/HttpConnection.java +++ b/src/main/java/org/jsoup/helper/HttpConnection.java @@ -125,11 +125,9 @@ public class HttpConnection implements Connection { static URL encodeUrl(URL u) { u = punyUrl(u); try { - // odd way to encode urls, but it works! - String urlS = u.toExternalForm(); // URL external form may have spaces which is illegal in new URL() (odd asymmetry) - urlS = urlS.replace(" ", "%20"); - final URI uri = new URI(urlS); - return new URL(uri.toASCIIString()); + // run the URL through URI, so components are encoded + URI uri = new URI(u.getProtocol(), u.getUserInfo(), u.getHost(), u.getPort(), u.getPath(), u.getQuery(), u.getRef()); + return uri.toURL(); } catch (URISyntaxException | MalformedURLException e) { // give up and return the original input return u; diff --git a/src/test/java/org/jsoup/helper/HttpConnectionTest.java b/src/test/java/org/jsoup/helper/HttpConnectionTest.java index 1fe5181..f7618fb 100644 --- a/src/test/java/org/jsoup/helper/HttpConnectionTest.java +++ b/src/test/java/org/jsoup/helper/HttpConnectionTest.java @@ -255,9 +255,9 @@ public class HttpConnectionTest { } @Test public void encodeUrl() throws MalformedURLException { - URL url1 = new URL("http://test.com/?q=white space"); + URL url1 = new URL("https://test.com/foo bar/[One]?q=white space#frag"); URL url2 = HttpConnection.encodeUrl(url1); - assertEquals("http://test.com/?q=white%20space", url2.toExternalForm()); + assertEquals("https://test.com/foo%20bar/%5BOne%5D?q=white%20space#frag", url2.toExternalForm()); } @Test public void noUrlThrowsValidationError() throws IOException {
https://github.com/jhy/jsoup.gitdiff --git a/src/main/java/org/jsoup/helper/HttpConnection.java b/src/main/java/org/jsoup/helper/HttpConnection.java
gitbug-java_data_jhy-jsoup.json_4
diff --git a/src/main/java/org/jsoup/nodes/TextNode.java b/src/main/java/org/jsoup/nodes/TextNode.java index 6d8ab63..df67a84 100644 --- a/src/main/java/org/jsoup/nodes/TextNode.java +++ b/src/main/java/org/jsoup/nodes/TextNode.java @@ -93,12 +93,14 @@ public class TextNode extends LeafNode { // if this text is just whitespace, and the next node will cause an indent, skip this text: Node next = nextSibling(); + Node prev = previousSibling(); boolean isBlank = isBlank(); boolean couldSkip = (next instanceof Element && ((Element) next).shouldIndent(out)) // next will indent - || (next instanceof TextNode && (((TextNode) next).isBlank())); // next is blank text, from re-parenting + || (next instanceof TextNode && (((TextNode) next).isBlank())) // next is blank text, from re-parenting + || (prev instanceof Element && ((Element) prev).isBlock()) + ; if (couldSkip && isBlank) return; - Node prev = previousSibling(); if ( (siblingIndex == 0 && parent != null && parent.tag().formatAsBlock() && !isBlank) || (out.outline() && siblingNodes().size() > 0 && !isBlank) || diff --git a/src/test/java/org/jsoup/nodes/ElementTest.java b/src/test/java/org/jsoup/nodes/ElementTest.java index 5c8b0b7..af23968 100644 --- a/src/test/java/org/jsoup/nodes/ElementTest.java +++ b/src/test/java/org/jsoup/nodes/ElementTest.java @@ -2359,7 +2359,7 @@ public class ElementTest { String html = "<body><div> <p> One Two </p> <a> Hello </a><p>\nSome text \n</p>\n </div>"; Document doc = Jsoup.parse(html); assertEquals("<div>\n" + - " <p>One Two</p> <a> Hello </a>\n" + + " <p>One Two</p><a> Hello </a>\n" + " <p>Some text</p>\n" + "</div>", doc.body().html()); } @@ -2380,4 +2380,11 @@ public class ElementTest { doc = Jsoup.parse(html); assertEquals("<foo>\n <bar />\n</foo>", doc.body().html()); } + + @Test void spanInBlockTrims() { + String html = "<p>Lorem ipsum</p>\n<span>Thanks</span>"; + Document doc = Jsoup.parse(html); + String outHtml = doc.body().html(); + assertEquals("<p>Lorem ipsum</p><span>Thanks</span>", outHtml); + } } \ No newline at end of file diff --git a/src/test/java/org/jsoup/parser/HtmlParserTest.java b/src/test/java/org/jsoup/parser/HtmlParserTest.java index eba7744..766bd1c 100644 --- a/src/test/java/org/jsoup/parser/HtmlParserTest.java +++ b/src/test/java/org/jsoup/parser/HtmlParserTest.java @@ -617,7 +617,7 @@ public class HtmlParserTest { @Test public void testSpanContents() { // like h1 tags, the spec says SPAN is phrasing only, but browsers and publisher treat span as a block tag Document doc = Jsoup.parse("<span>Hello <div>there</div> <span>now</span></span>"); - assertEquals("<span>Hello <div>there</div> <span>now</span></span>", TextUtil.stripNewlines(doc.body().html())); + assertEquals("<span>Hello <div>there</div><span>now</span></span>", TextUtil.stripNewlines(doc.body().html())); } @Test public void testNoImagesInNoScriptInHead() { @@ -638,13 +638,13 @@ public class HtmlParserTest { @Test public void testAFlowContents() { // html5 has <a> as either phrasing or block Document doc = Jsoup.parse("<a>Hello <div>there</div> <span>now</span></a>"); - assertEquals("<a>Hello <div>there</div> <span>now</span></a>", TextUtil.stripNewlines(doc.body().html())); + assertEquals("<a>Hello <div>there</div><span>now</span></a>", TextUtil.stripNewlines(doc.body().html())); } @Test public void testFontFlowContents() { // html5 has no definition of <font>; often used as flow Document doc = Jsoup.parse("<font>Hello <div>there</div> <span>now</span></font>"); - assertEquals("<font>Hello <div>there</div> <span>now</span></font>", TextUtil.stripNewlines(doc.body().html())); + assertEquals("<font>Hello <div>there</div><span>now</span></font>", TextUtil.stripNewlines(doc.body().html())); } @Test public void handlesMisnestedTagsBI() { @@ -727,7 +727,7 @@ public class HtmlParserTest { " <td><p><i>Three</i></p><p><i>Four</i></p></td>\n" + " </tr>\n" + " </tbody>\n" + - " </table> <p>Five</p></b>"; + " </table><p>Five</p></b>"; assertEquals(want, doc.body().html()); } @@ -1487,7 +1487,7 @@ public class HtmlParserTest { String html = "<a>\n<b>\n<div>\n<a>test</a>\n</div>\n</b>\n</a>"; Document doc = Jsoup.parse(html); assertNotNull(doc); - assertEquals("<a> <b> </b></a><b><div><a> </a><a>test</a></div> </b>", TextUtil.stripNewlines(doc.body().html())); + assertEquals("<a> <b> </b></a><b><div><a> </a><a>test</a></div></b>", TextUtil.stripNewlines(doc.body().html())); } @Test public void tagsMustStartWithAscii() {
https://github.com/jhy/jsoup.gitdiff --git a/src/main/java/org/jsoup/nodes/TextNode.java b/src/main/java/org/jsoup/nodes/TextNode.java
gitbug-java_data_jhy-jsoup.json_5
diff --git a/src/main/java/org/jsoup/nodes/Node.java b/src/main/java/org/jsoup/nodes/Node.java index eee9291..f271b17 100644 --- a/src/main/java/org/jsoup/nodes/Node.java +++ b/src/main/java/org/jsoup/nodes/Node.java @@ -480,6 +480,8 @@ public abstract class Node implements Cloneable { protected void replaceChild(Node out, Node in) { Validate.isTrue(out.parentNode == this); Validate.notNull(in); + if (out == in) return; // no-op self replacement + if (in.parentNode != null) in.parentNode.removeChild(in); diff --git a/src/test/java/org/jsoup/nodes/ElementTest.java b/src/test/java/org/jsoup/nodes/ElementTest.java index cd82348..4779668 100644 --- a/src/test/java/org/jsoup/nodes/ElementTest.java +++ b/src/test/java/org/jsoup/nodes/ElementTest.java @@ -2440,4 +2440,16 @@ public class ElementTest { String outHtml = doc.body().html(); assertEquals("<p>Lorem ipsum</p><span>Thanks</span>", outHtml); } + + @Test void replaceWithSelf() { + // https://github.com/jhy/jsoup/issues/1843 + Document doc = Jsoup.parse("<p>One<p>Two"); + Elements ps = doc.select("p"); + Element first = ps.first(); + + assertNotNull(first); + first.replaceWith(first); + assertEquals(ps.get(1), first.nextSibling()); + assertEquals("<p>One</p>\n<p>Two</p>", first.parent().html()); + } } \ No newline at end of file
https://github.com/jhy/jsoup.gitdiff --git a/src/main/java/org/jsoup/nodes/Node.java b/src/main/java/org/jsoup/nodes/Node.java
gitbug-java_data_jhy-jsoup.json_6
diff --git a/src/main/java/org/jsoup/nodes/TextNode.java b/src/main/java/org/jsoup/nodes/TextNode.java index eae444a..7a7f00a 100644 --- a/src/main/java/org/jsoup/nodes/TextNode.java +++ b/src/main/java/org/jsoup/nodes/TextNode.java @@ -98,7 +98,7 @@ public class TextNode extends LeafNode { boolean isBlank = isBlank(); boolean couldSkip = (next instanceof Element && ((Element) next).shouldIndent(out)) // next will indent || (next instanceof TextNode && (((TextNode) next).isBlank())) // next is blank text, from re-parenting - || (prev instanceof Element && ((Element) prev).isBlock()) + || (prev instanceof Element && (((Element) prev).isBlock() || prev.isNode("br"))) // br is a bit special - make sure we don't get a dangling blank line, but not a block otherwise wraps in head ; if (couldSkip && isBlank) return; diff --git a/src/test/java/org/jsoup/nodes/ElementTest.java b/src/test/java/org/jsoup/nodes/ElementTest.java index bc17127..20954ef 100644 --- a/src/test/java/org/jsoup/nodes/ElementTest.java +++ b/src/test/java/org/jsoup/nodes/ElementTest.java @@ -2286,6 +2286,12 @@ public class ElementTest { assertEquals("<p>Hello<br>\n there<br>\n now.</p>", doc.body().html()); } + @Test void prettyprintBrInBlock() { + String html = "<div><br> </div>"; + Document doc = Jsoup.parse(html); + assertEquals("<div>\n <br>\n</div>", doc.body().html()); // not div\n br\n \n/div + } + @Test void preformatFlowsToChildTextNodes() { // https://github.com/jhy/jsoup/issues/1776 String html = "<div><pre>One\n<span>\nTwo</span>\n <span> \nThree</span>\n <span>Four <span>Five</span>\n Six\n</pre>";
https://github.com/jhy/jsoup.gitdiff --git a/src/main/java/org/jsoup/nodes/TextNode.java b/src/main/java/org/jsoup/nodes/TextNode.java
gitbug-java_data_jhy-jsoup.json_7
diff --git a/src/main/java/org/jsoup/helper/HttpConnection.java b/src/main/java/org/jsoup/helper/HttpConnection.java index d183a52..88595c3 100644 --- a/src/main/java/org/jsoup/helper/HttpConnection.java +++ b/src/main/java/org/jsoup/helper/HttpConnection.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; +import java.io.UnsupportedEncodingException; import java.net.CookieManager; import java.net.CookieStore; import java.net.HttpURLConnection; @@ -30,6 +31,7 @@ import java.net.Proxy; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; +import java.net.URLDecoder; import java.net.URLEncoder; import java.nio.Buffer; import java.nio.ByteBuffer; @@ -127,14 +129,21 @@ public class HttpConnection implements Connection { u = punyUrl(u); try { // run the URL through URI, so components are encoded - URI uri = new URI(u.getProtocol(), u.getUserInfo(), u.getHost(), u.getPort(), u.getPath(), u.getQuery(), u.getRef()); + URI uri = new URI( + u.getProtocol(), decodePart(u.getUserInfo()), u.getHost(), u.getPort(), + decodePart(u.getPath()), decodePart(u.getQuery()), decodePart(u.getRef())); return uri.toURL(); - } catch (URISyntaxException | MalformedURLException e) { + } catch (URISyntaxException | MalformedURLException | UnsupportedEncodingException e) { // give up and return the original input return u; } } + @Nullable private static String decodePart(@Nullable String encoded) throws UnsupportedEncodingException { + if (encoded == null) return null; + return URLDecoder.decode(encoded, UTF_8.name()); + } + /** Convert an International URL to a Punycode URL. @param url input URL that may include an international hostname diff --git a/src/test/java/org/jsoup/helper/HttpConnectionTest.java b/src/test/java/org/jsoup/helper/HttpConnectionTest.java index f7618fb..b655f8f 100644 --- a/src/test/java/org/jsoup/helper/HttpConnectionTest.java +++ b/src/test/java/org/jsoup/helper/HttpConnectionTest.java @@ -260,6 +260,20 @@ public class HttpConnectionTest { assertEquals("https://test.com/foo%20bar/%5BOne%5D?q=white%20space#frag", url2.toExternalForm()); } + @Test void encodedUrlDoesntDoubleEncode() throws MalformedURLException { + URL url1 = new URL("https://test.com/foo bar/[One]?q=white space#frag ment"); + URL url2 = HttpConnection.encodeUrl(url1); + URL url3 = HttpConnection.encodeUrl(url2); + assertEquals("https://test.com/foo%20bar/%5BOne%5D?q=white%20space#frag%20ment", url2.toExternalForm()); + assertEquals("https://test.com/foo%20bar/%5BOne%5D?q=white%20space#frag%20ment", url3.toExternalForm()); + } + + @Test void connectToEncodedUrl() { + Connection connect = Jsoup.connect("https://example.com/a%20b%20c?query+string"); + URL url = connect.request().url(); + assertEquals("https://example.com/a%20b%20c?query%20string", url.toExternalForm()); + } + @Test public void noUrlThrowsValidationError() throws IOException { HttpConnection con = new HttpConnection(); boolean threw = false;
https://github.com/jhy/jsoup.gitdiff --git a/src/main/java/org/jsoup/helper/HttpConnection.java b/src/main/java/org/jsoup/helper/HttpConnection.java
gitbug-java_data_jhy-jsoup.json_8
diff --git a/src/main/java/org/jsoup/parser/HtmlTreeBuilder.java b/src/main/java/org/jsoup/parser/HtmlTreeBuilder.java index 7a9c0be..715a995 100644 --- a/src/main/java/org/jsoup/parser/HtmlTreeBuilder.java +++ b/src/main/java/org/jsoup/parser/HtmlTreeBuilder.java @@ -838,6 +838,7 @@ public class HtmlTreeBuilder extends TreeBuilder { return onStack(formattingElements, el); } + @Nullable Element getActiveFormattingElement(String nodeName) { for (int pos = formattingElements.size() -1; pos >= 0; pos--) { Element next = formattingElements.get(pos); diff --git a/src/main/java/org/jsoup/parser/HtmlTreeBuilderState.java b/src/main/java/org/jsoup/parser/HtmlTreeBuilderState.java index 354b217..1ab9f7a 100644 --- a/src/main/java/org/jsoup/parser/HtmlTreeBuilderState.java +++ b/src/main/java/org/jsoup/parser/HtmlTreeBuilderState.java @@ -611,7 +611,7 @@ enum HtmlTreeBuilderState { } tb.insert(startTag); break; - // static final String[] InBodyStartOptions = new String[]{"optgroup", "option"}; + case "optgroup": case "option": if (tb.currentElementIs("option")) @@ -619,19 +619,27 @@ enum HtmlTreeBuilderState { tb.reconstructFormattingElements(); tb.insert(startTag); break; - // static final String[] InBodyStartRuby = new String[]{"rp", "rt"}; + + case "rb": + case "rtc": + if (tb.onStack("ruby")) { + tb.generateImpliedEndTags(); + if (!tb.currentElementIs("ruby")) + tb.error(this); + } + tb.insert(startTag); + break; + case "rp": case "rt": if (tb.inScope("ruby")) { - tb.generateImpliedEndTags(); - if (!tb.currentElementIs("ruby")) { + tb.generateImpliedEndTags("rtc"); + if (!tb.currentElementIs("rtc") && !tb.currentElementIs("ruby")) tb.error(this); - tb.popStackToBefore("ruby"); // i.e. close up to but not include name - } - tb.insert(startTag); } - // todo - is this right? drops rp, rt if ruby not in scope? + tb.insert(startTag); break; + // InBodyStartEmptyFormatters: case "area": case "br": diff --git a/src/test/java/org/jsoup/parser/HtmlParserTest.java b/src/test/java/org/jsoup/parser/HtmlParserTest.java index d2761aa..283ac72 100644 --- a/src/test/java/org/jsoup/parser/HtmlParserTest.java +++ b/src/test/java/org/jsoup/parser/HtmlParserTest.java @@ -1665,4 +1665,16 @@ public class HtmlParserTest { Document doc = Jsoup.parse("<html id=1 class=foo><body><html><p>One"); assertEquals("<html id=\"1\" class=\"foo\"><head></head><body><p>One</p></body></html>", TextUtil.stripNewlines(doc.html())); } + + @Test void supportsRuby() { + String html = "<ruby><rbc><rb>10</rb><rb>31</rb><rb>2002</rb></rbc><rtc><rt>Month</rt><rt>Day</rt><rt>Year</rt></rtc><rtc><rt>Expiration Date</rt><rp>(*)</rtc></ruby>"; + Parser parser = Parser.htmlParser(); + parser.setTrackErrors(10); + Document doc = Jsoup.parse(html); + assertEquals(0, parser.getErrors().size()); + Element ruby = doc.expectFirst("ruby"); + assertEquals( + "<ruby><rbc><rb>10</rb><rb>31</rb><rb>2002</rb></rbc><rtc><rt>Month</rt><rt>Day</rt><rt>Year</rt></rtc><rtc><rt>Expiration Date</rt><rp>(*)</rp></rtc></ruby>", + TextUtil.stripNewlines(ruby.outerHtml())); + } }
https://github.com/jhy/jsoup.gitdiff --git a/src/main/java/org/jsoup/parser/HtmlTreeBuilder.java b/src/main/java/org/jsoup/parser/HtmlTreeBuilder.java
gitbug-java_data_jhy-jsoup.json_9
diff --git a/src/main/java/org/jsoup/nodes/Element.java b/src/main/java/org/jsoup/nodes/Element.java index 507fce9..ad3b022 100644 --- a/src/main/java/org/jsoup/nodes/Element.java +++ b/src/main/java/org/jsoup/nodes/Element.java @@ -1846,9 +1846,15 @@ public class Element extends Node { } private boolean isInlineable(Document.OutputSettings out) { - return tag().isInline() - && (parent() == null || parent().isBlock()) - && previousSibling() != null + if (!tag.isInline()) + return false; + + final Node prev = previousSibling(); + boolean isFirst = siblingIndex == 0; + if (siblingIndex == 1 && prev instanceof TextNode && (((TextNode) prev).isBlank())) + isFirst = true; + return (parent() == null || parent().isBlock()) + && !isFirst && !out.outline(); } } diff --git a/src/test/java/org/jsoup/nodes/ElementTest.java b/src/test/java/org/jsoup/nodes/ElementTest.java index 0887a4e..5f54cbd 100644 --- a/src/test/java/org/jsoup/nodes/ElementTest.java +++ b/src/test/java/org/jsoup/nodes/ElementTest.java @@ -2343,6 +2343,23 @@ public class ElementTest { assertEquals(expectOwn, div.child(0).wholeOwnText()); } + @Test void inlineInBlockShouldIndent() { + // was inconsistent between <div>\n<span> and <div><span> - former would print inline, latter would wrap(!) + String html = "<div>One <span>Hello</span><span>!</span></div><div>\n<span>There</span></div><div> <span>Now</span></div>"; + Document doc = Jsoup.parse(html); + assertEquals( + "<div>\n" + + " One <span>Hello</span><span>!</span>\n" + + "</div>\n" + + "<div>\n" + + " <span>There</span>\n" + + "</div>\n" + + "<div>\n" + + " <span>Now</span>\n" + + "</div>", + doc.body().html()); + } + @Test void testExpectFirst() { Document doc = Jsoup.parse("<p>One</p><p>Two <span>Three</span> <span>Four</span>"); @@ -2445,7 +2462,9 @@ public class ElementTest { @Test void divAInlineable() { String html = "<body><div> <a>Text</a>"; Document doc = Jsoup.parse(html); - assertEquals("<div><a>Text</a>\n</div>", doc.body().html()); + assertEquals("<div>\n" + + " <a>Text</a>\n" + + "</div>", doc.body().html()); } @Test void noDanglingSpaceAfterCustomElement() { diff --git a/src/test/java/org/jsoup/parser/HtmlTreeBuilderStateTest.java b/src/test/java/org/jsoup/parser/HtmlTreeBuilderStateTest.java index f05ee26..c2dbfe3 100644 --- a/src/test/java/org/jsoup/parser/HtmlTreeBuilderStateTest.java +++ b/src/test/java/org/jsoup/parser/HtmlTreeBuilderStateTest.java @@ -75,7 +75,8 @@ public class HtmlTreeBuilderStateTest { String s = Jsoup.parse(html).toString(); assertEquals("<html>\n" + " <head></head>\n" + - " <body><a href=\"#1\"> </a>\n" + + " <body>\n" + + " <a href=\"#1\"> </a>\n" + " <div>\n" + " <a href=\"#1\"> </a><a href=\"#2\">child</a>\n" + " </div>\n" + @@ -99,7 +100,8 @@ public class HtmlTreeBuilderStateTest { String s = Jsoup.parse(html).toString(); assertEquals("<html>\n" + " <head></head>\n" + - " <body><a href=\"#1\"> </a>\n" + + " <body>\n" + + " <a href=\"#1\"> </a>\n" + " <div>\n" + " <a href=\"#1\"> </a>\n" + " <div>\n" + diff --git a/src/test/java/org/jsoup/select/ElementsTest.java b/src/test/java/org/jsoup/select/ElementsTest.java index eab17c2..d189575 100644 --- a/src/test/java/org/jsoup/select/ElementsTest.java +++ b/src/test/java/org/jsoup/select/ElementsTest.java @@ -193,7 +193,9 @@ public class ElementsTest { String h = "<div><font>One</font> <font><a href=\"/\">Two</a></font></div"; Document doc = Jsoup.parse(h); doc.select("font").unwrap(); - assertEquals("<div>One <a href=\"/\">Two</a></div>", TextUtil.stripNewlines(doc.body().html())); + assertEquals("<div>\n" + + " One <a href=\"/\">Two</a>\n" + + "</div>", doc.body().html()); } @Test public void unwrapP() {
https://github.com/jhy/jsoup.gitdiff --git a/src/main/java/org/jsoup/nodes/Element.java b/src/main/java/org/jsoup/nodes/Element.java
gitbug-java_data_jhy-jsoup.json_10
diff --git a/src/main/java/org/jsoup/parser/Tag.java b/src/main/java/org/jsoup/parser/Tag.java index d573033..366bc63 100644 --- a/src/main/java/org/jsoup/parser/Tag.java +++ b/src/main/java/org/jsoup/parser/Tag.java @@ -242,7 +242,7 @@ public class Tag implements Cloneable { }; private static final String[] inlineTags = { "object", "base", "font", "tt", "i", "b", "u", "big", "small", "em", "strong", "dfn", "code", "samp", "kbd", - "var", "cite", "abbr", "time", "acronym", "mark", "ruby", "rt", "rp", "a", "img", "br", "wbr", "map", "q", + "var", "cite", "abbr", "time", "acronym", "mark", "ruby", "rt", "rp", "rtc", "a", "img", "br", "wbr", "map", "q", "sub", "sup", "bdo", "iframe", "embed", "span", "input", "select", "textarea", "label", "button", "optgroup", "option", "legend", "datalist", "keygen", "output", "progress", "meter", "area", "param", "source", "track", "summary", "command", "device", "area", "basefont", "bgsound", "menuitem", "param", "source", "track", diff --git a/src/test/java/org/jsoup/nodes/ElementTest.java b/src/test/java/org/jsoup/nodes/ElementTest.java index 5f54cbd..a3538f9 100644 --- a/src/test/java/org/jsoup/nodes/ElementTest.java +++ b/src/test/java/org/jsoup/nodes/ElementTest.java @@ -2676,4 +2676,10 @@ public class ElementTest { doc.body().outerHtml(builder); assertEquals("<body>\n <div>\n One\n </div>\n</body>", builder.toString()); } -} \ No newline at end of file + + @Test void rubyInline() { + String html = "<ruby>T<rp>(</rp><rtc>!</rtc><rt>)</rt></ruby>"; + Document doc = Jsoup.parse(html); + assertEquals(html, doc.body().html()); + } +}
https://github.com/jhy/jsoup.gitdiff --git a/src/main/java/org/jsoup/parser/Tag.java b/src/main/java/org/jsoup/parser/Tag.java
gitbug-java_data_jhy-jsoup.json_11
diff --git a/src/main/java/org/jsoup/nodes/Comment.java b/src/main/java/org/jsoup/nodes/Comment.java index 8ac8f70..f7fc9f3 100644 --- a/src/main/java/org/jsoup/nodes/Comment.java +++ b/src/main/java/org/jsoup/nodes/Comment.java @@ -38,7 +38,7 @@ public class Comment extends LeafNode { @Override void outerHtmlHead(Appendable accum, int depth, Document.OutputSettings out) throws IOException { - if (out.prettyPrint() && ((siblingIndex() == 0 && parentNode instanceof Element && ((Element) parentNode).tag().formatAsBlock()) || (out.outline() ))) + if (out.prettyPrint() && ((isEffectivelyFirst() && parentNode instanceof Element && ((Element) parentNode).tag().formatAsBlock()) || (out.outline() ))) indent(accum, depth, out); accum .append("<!--") diff --git a/src/main/java/org/jsoup/nodes/Element.java b/src/main/java/org/jsoup/nodes/Element.java index 2432fef..ab1b748 100644 --- a/src/main/java/org/jsoup/nodes/Element.java +++ b/src/main/java/org/jsoup/nodes/Element.java @@ -1849,13 +1849,8 @@ public class Element extends Node { private boolean isInlineable(Document.OutputSettings out) { if (!tag.isInline()) return false; - - final Node prev = previousSibling(); - boolean isFirst = siblingIndex == 0; - if (siblingIndex == 1 && prev instanceof TextNode && (((TextNode) prev).isBlank())) - isFirst = true; return (parent() == null || parent().isBlock()) - && !isFirst + && !isEffectivelyFirst() && !out.outline(); } } diff --git a/src/main/java/org/jsoup/nodes/Node.java b/src/main/java/org/jsoup/nodes/Node.java index fc5ac3b..851bd8a 100644 --- a/src/main/java/org/jsoup/nodes/Node.java +++ b/src/main/java/org/jsoup/nodes/Node.java @@ -762,6 +762,16 @@ public abstract class Node implements Cloneable { return normalName().equals(normalName); } + /** Test if this node is the first child, or first following blank text. */ + final boolean isEffectivelyFirst() { + if (siblingIndex == 0) return true; + if (siblingIndex == 1) { + final Node prev = previousSibling(); + return prev instanceof TextNode && (((TextNode) prev).isBlank()); + } + return false; + } + /** * Gets this node's outer HTML. * @return outer HTML. diff --git a/src/test/java/org/jsoup/nodes/CommentTest.java b/src/test/java/org/jsoup/nodes/CommentTest.java index fe1c136..c622f18 100644 --- a/src/test/java/org/jsoup/nodes/CommentTest.java +++ b/src/test/java/org/jsoup/nodes/CommentTest.java @@ -41,6 +41,20 @@ public class CommentTest { assertEquals("<!-- a simple comment -->", c1.outerHtml()); } + @Test void stableIndentInBlock() { + String html = "<div><!-- comment --> Text</div><p><!-- comment --> Text</p>"; + Document doc = Jsoup.parse(html); + String out = doc.body().html(); + assertEquals("<div>\n" + + " <!-- comment --> Text\n" + + "</div>\n" + + "<p><!-- comment --> Text</p>", out); + + Document doc2 = Jsoup.parse(out); + String out2 = doc2.body().html(); + assertEquals(out, out2); + } + @Test public void testClone() { Comment c1 = comment.clone(); diff --git a/src/test/java/org/jsoup/parser/HtmlParserTest.java b/src/test/java/org/jsoup/parser/HtmlParserTest.java index 1f83518..26b546d 100644 --- a/src/test/java/org/jsoup/parser/HtmlParserTest.java +++ b/src/test/java/org/jsoup/parser/HtmlParserTest.java @@ -1247,7 +1247,7 @@ public class HtmlParserTest { File in = ParseTest.getFile("/htmltests/comments.html"); Document doc = Jsoup.parse(in, "UTF-8"); - assertEquals("<!--?xml version=\"1.0\" encoding=\"utf-8\"?--><!-- so --> <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><!-- what --> <html xml:lang=\"en\" lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><!-- now --> <head><!-- then --> <meta http-equiv=\"Content-type\" content=\"text/html; charset=utf-8\"> <title>A Certain Kind of Test</title> </head> <body> <h1>Hello</h1>h1&gt; (There is a UTF8 hidden BOM at the top of this file.) </body> </html>", + assertEquals("<!--?xml version=\"1.0\" encoding=\"utf-8\"?--><!-- so --> <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><!-- what --> <html xml:lang=\"en\" lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"> <!-- now --> <head> <!-- then --> <meta http-equiv=\"Content-type\" content=\"text/html; charset=utf-8\"> <title>A Certain Kind of Test</title> </head> <body> <h1>Hello</h1>h1&gt; (There is a UTF8 hidden BOM at the top of this file.) </body> </html>", StringUtil.normaliseWhitespace(doc.html())); assertEquals("A Certain Kind of Test", doc.head().select("title").text());
https://github.com/jhy/jsoup.gitdiff --git a/src/main/java/org/jsoup/nodes/Comment.java b/src/main/java/org/jsoup/nodes/Comment.java
gitbug-java_data_jhy-jsoup.json_12
diff --git a/src/main/java/org/jsoup/nodes/Element.java b/src/main/java/org/jsoup/nodes/Element.java index ad3b022..2432fef 100644 --- a/src/main/java/org/jsoup/nodes/Element.java +++ b/src/main/java/org/jsoup/nodes/Element.java @@ -1670,7 +1670,7 @@ public class Element extends Node { } boolean shouldIndent(final Document.OutputSettings out) { - return out.prettyPrint() && isFormatAsBlock(out) && !isInlineable(out); + return out.prettyPrint() && isFormatAsBlock(out) && !isInlineable(out) && !preserveWhitespace(parentNode); } @Override @@ -1701,7 +1701,8 @@ public class Element extends Node { void outerHtmlTail(Appendable accum, int depth, Document.OutputSettings out) throws IOException { if (!(childNodes.isEmpty() && tag.isSelfClosing())) { if (out.prettyPrint() && (!childNodes.isEmpty() && ( - tag.formatAsBlock() || (out.outline() && (childNodes.size()>1 || (childNodes.size()==1 && (childNodes.get(0) instanceof Element)))) + (tag.formatAsBlock() && !preserveWhitespace(parentNode)) || + (out.outline() && (childNodes.size()>1 || (childNodes.size()==1 && (childNodes.get(0) instanceof Element)))) ))) indent(accum, depth, out); accum.append("</").append(tagName()).append('>'); diff --git a/src/test/java/org/jsoup/nodes/ElementTest.java b/src/test/java/org/jsoup/nodes/ElementTest.java index a3538f9..493179a 100644 --- a/src/test/java/org/jsoup/nodes/ElementTest.java +++ b/src/test/java/org/jsoup/nodes/ElementTest.java @@ -157,6 +157,14 @@ public class ElementTest { assertEquals("<pre><code><span><b>code\n\ncode</b></span></code></pre>", doc.body().html()); } + @Test void doesNotWrapBlocksInPre() { + // https://github.com/jhy/jsoup/issues/1891 + String h = "<pre><span><foo><div>TEST\n TEST</div></foo></span></pre>"; + Document doc = Jsoup.parse(h); + assertEquals("TEST\n TEST", doc.wholeText()); + assertEquals(h, doc.body().html()); + } + @Test public void testBrHasSpace() { Document doc = Jsoup.parse("<p>Hello<br>there</p>");
https://github.com/jhy/jsoup.gitdiff --git a/src/main/java/org/jsoup/nodes/Element.java b/src/main/java/org/jsoup/nodes/Element.java
gitbug-java_data_jhy-jsoup.json_13
diff --git a/src/main/java/org/jsoup/nodes/Element.java b/src/main/java/org/jsoup/nodes/Element.java index ab1b748..5142fa2 100644 --- a/src/main/java/org/jsoup/nodes/Element.java +++ b/src/main/java/org/jsoup/nodes/Element.java @@ -1851,6 +1851,7 @@ public class Element extends Node { return false; return (parent() == null || parent().isBlock()) && !isEffectivelyFirst() - && !out.outline(); + && !out.outline() + && !isNode("br"); } } diff --git a/src/test/java/org/jsoup/nodes/ElementTest.java b/src/test/java/org/jsoup/nodes/ElementTest.java index 493179a..0bb433c 100644 --- a/src/test/java/org/jsoup/nodes/ElementTest.java +++ b/src/test/java/org/jsoup/nodes/ElementTest.java @@ -2314,6 +2314,17 @@ public class ElementTest { assertEquals("<div>\n <br>\n</div>", doc.body().html()); // not div\n br\n \n/div } + @Test void prettyprintBrWhenNotFirstChild() { + // https://github.com/jhy/jsoup/issues/1911 + String h = "<div><p><br>Foo</p><br></div>"; + Document doc = Jsoup.parse(h); + assertEquals("<div>\n" + + " <p><br>\n Foo</p>\n" + + " <br>\n" + + "</div>", doc.body().html()); + // br gets wrapped if in div, but not in p (block vs inline), but always wraps after + } + @Test void preformatFlowsToChildTextNodes() { // https://github.com/jhy/jsoup/issues/1776 String html = "<div><pre>One\n<span>\nTwo</span>\n <span> \nThree</span>\n <span>Four <span>Five</span>\n Six\n</pre>"; diff --git a/src/test/java/org/jsoup/parser/XmlTreeBuilderTest.java b/src/test/java/org/jsoup/parser/XmlTreeBuilderTest.java index 227dd09..d359a52 100644 --- a/src/test/java/org/jsoup/parser/XmlTreeBuilderTest.java +++ b/src/test/java/org/jsoup/parser/XmlTreeBuilderTest.java @@ -94,7 +94,7 @@ public class XmlTreeBuilderTest { public void testDoesNotForceSelfClosingKnownTags() { // html will force "<br>one</br>" to logically "<br />One<br />". XML should be stay "<br>one</br> -- don't recognise tag. Document htmlDoc = Jsoup.parse("<br>one</br>"); - assertEquals("<br>\none<br>", htmlDoc.body().html()); + assertEquals("<br>\none\n<br>", htmlDoc.body().html()); Document xmlDoc = Jsoup.parse("<br>one</br>", "", Parser.xmlParser()); assertEquals("<br>one</br>", xmlDoc.html());
https://github.com/jhy/jsoup.gitdiff --git a/src/main/java/org/jsoup/nodes/Element.java b/src/main/java/org/jsoup/nodes/Element.java
gitbug-java_data_jhy-jsoup.json_14
diff --git a/src/main/java/org/jsoup/helper/UrlBuilder.java b/src/main/java/org/jsoup/helper/UrlBuilder.java index c62d064..89f46a1 100644 --- a/src/main/java/org/jsoup/helper/UrlBuilder.java +++ b/src/main/java/org/jsoup/helper/UrlBuilder.java @@ -17,8 +17,8 @@ import static org.jsoup.helper.DataUtil.UTF_8; /** A utility class to normalize input URLs. jsoup internal; API subject to change. - <p>Normalization includes puny-coding the host, and encoding non-ascii path components. The query-string - is left mostly as-is, to avoid inadvertently/incorrectly decoding a desired '+' literal ('%2B') as a ' '.</p> + <p>Normalization includes puny-coding the host, and encoding non-ascii path components. Any non-ascii characters in + the query string (or the fragment/anchor) are escaped, but any existing escapes in those components are preserved.</p> */ final class UrlBuilder { URL u; @@ -47,19 +47,20 @@ final class UrlBuilder { StringBuilder sb = StringUtil.borrowBuilder().append(normUrl); if (q != null) { sb.append('?'); - sb.append(normalizeQuery(StringUtil.releaseBuilder(q))); + appendToAscii(StringUtil.releaseBuilder(q), true, sb); } if (u.getRef() != null) { sb.append('#'); - sb.append(normalizeRef(u.getRef())); + appendToAscii(u.getRef(), false, sb); } normUrl = StringUtil.releaseBuilder(sb); } u = new URL(normUrl); return u; - } catch (MalformedURLException | URISyntaxException e) { + } catch (MalformedURLException | URISyntaxException | UnsupportedEncodingException e) { // we assert here so that any incomplete normalization issues can be caught in devel. but in practise, - // the remote end will be able to handle it, so in prod we just pass the original URL + // the remote end will be able to handle it, so in prod we just pass the original URL. + // The UnsupportedEncodingException would never happen as always UTF8 assert Validate.assertFail(e.toString()); return u; } @@ -84,14 +85,19 @@ final class UrlBuilder { } } - private static String normalizeQuery(String q) { - // minimal space normal; other characters left as supplied - if generated from jsoup data, will be encoded - return q.replace(' ', '+'); - } - - private static String normalizeRef(String r) { - // minimal space normal; other characters left as supplied - return r.replace(" ", "%20"); + private static void appendToAscii(String s, boolean spaceAsPlus, StringBuilder sb) throws UnsupportedEncodingException { + // minimal normalization of Unicode -> Ascii, and space normal. Existing escapes are left as-is. + for (int i = 0; i < s.length(); i++) { + int c = s.codePointAt(i); + if (c == ' ') { + sb.append(spaceAsPlus ? '+' : "%20"); + } else if (c > 127) { // out of ascii range + sb.append(URLEncoder.encode(new String(Character.toChars(c)), UTF_8.name())); + // ^^ is a bit heavy-handed - if perf critical, we could optimize + } else { + sb.append((char) c); + } + } } diff --git a/src/main/java/org/jsoup/internal/StringUtil.java b/src/main/java/org/jsoup/internal/StringUtil.java index 73a589b..a24cad5 100644 --- a/src/main/java/org/jsoup/internal/StringUtil.java +++ b/src/main/java/org/jsoup/internal/StringUtil.java @@ -256,7 +256,7 @@ public final class StringUtil { final int len = haystack.length; for (int i = 0; i < len; i++) { if (haystack[i].equals(needle)) - return true; + return true; } return false; } diff --git a/src/test/java/org/jsoup/integration/ConnectTest.java b/src/test/java/org/jsoup/integration/ConnectTest.java index e453cf9..07f9d2e 100644 --- a/src/test/java/org/jsoup/integration/ConnectTest.java +++ b/src/test/java/org/jsoup/integration/ConnectTest.java @@ -3,6 +3,7 @@ package org.jsoup.integration; import org.jsoup.Connection; import org.jsoup.HttpStatusException; import org.jsoup.Jsoup; +import org.jsoup.helper.DataUtil; import org.jsoup.helper.W3CDom; import org.jsoup.integration.servlets.*; import org.jsoup.internal.StringUtil; @@ -20,6 +21,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; +import java.net.URLDecoder; import java.util.List; import java.util.Map; @@ -751,10 +753,11 @@ public class ConnectTest { } @Test void fetchUnicodeUrl() throws IOException { - String url = EchoServlet.Url + "/✔/?%E9%8D%B5=%E5%80%A4"; // encoded 鍵=値 + String url = EchoServlet.Url + "/✔/?鍵=値"; Document doc = Jsoup.connect(url).get(); assertEquals("/✔/", ihVal("Path Info", doc)); assertEquals("%E9%8D%B5=%E5%80%A4", ihVal("Query String", doc)); + assertEquals("鍵=値", URLDecoder.decode(ihVal("Query String", doc), DataUtil.UTF_8.name())); } }
https://github.com/jhy/jsoup.gitdiff --git a/src/main/java/org/jsoup/helper/UrlBuilder.java b/src/main/java/org/jsoup/helper/UrlBuilder.java
gitbug-java_data_jhy-jsoup.json_15
diff --git a/src/main/java/org/jsoup/parser/HtmlTreeBuilder.java b/src/main/java/org/jsoup/parser/HtmlTreeBuilder.java index 785643e..9de525b 100644 --- a/src/main/java/org/jsoup/parser/HtmlTreeBuilder.java +++ b/src/main/java/org/jsoup/parser/HtmlTreeBuilder.java @@ -301,9 +301,14 @@ public class HtmlTreeBuilder extends TreeBuilder { insertNode(comment, commentToken); } + /** Inserts the provided character token into the current element. */ void insert(Token.Character characterToken) { + final Element el = currentElement(); // will be doc if no current element; allows for whitespace to be inserted into the doc root object (not on the stack) + insert(characterToken, el); + } + + void insert(Token.Character characterToken, Element el) { final Node node; - Element el = currentElement(); // will be doc if no current element; allows for whitespace to be inserted into the doc root object (not on the stack) final String tagName = el.normalName(); final String data = characterToken.getData(); @@ -317,6 +322,7 @@ public class HtmlTreeBuilder extends TreeBuilder { onNodeInserted(node, characterToken); } + /** Inserts the provided character token into the provided element. Use when not going onto stack element */ private void insertNode(Node node, @Nullable Token token) { // if the stack hasn't been set up yet, elements (doctype, comments) go into the doc if (stack.isEmpty()) @@ -632,6 +638,20 @@ public class HtmlTreeBuilder extends TreeBuilder { return false; } + /** Tests if there is some element on the stack that is not in the provided set. */ + boolean onStackNot(String[] allowedTags) { + final int bottom = stack.size() -1; + final int top = bottom > MaxScopeSearchDepth ? bottom - MaxScopeSearchDepth : 0; + // don't walk too far up the tree + + for (int pos = bottom; pos >= top; pos--) { + final String elName = stack.get(pos).normalName(); + if (!inSorted(elName, allowedTags)) + return true; + } + return false; + } + void setHeadElement(Element headElement) { this.headElement = headElement; } diff --git a/src/main/java/org/jsoup/parser/HtmlTreeBuilderState.java b/src/main/java/org/jsoup/parser/HtmlTreeBuilderState.java index baa16c4..99edf8c 100644 --- a/src/main/java/org/jsoup/parser/HtmlTreeBuilderState.java +++ b/src/main/java/org/jsoup/parser/HtmlTreeBuilderState.java @@ -310,7 +310,8 @@ enum HtmlTreeBuilderState { case EOF: if (tb.templateModeSize() > 0) return tb.process(t, InTemplate); - // todo: error if stack contains something not dd, dt, li, p, tbody, td, tfoot, th, thead, tr, body, html + if (tb.onStackNot(InBodyEndOtherErrors)) + tb.error(this); // stop parsing break; } @@ -726,16 +727,22 @@ enum HtmlTreeBuilderState { tb.error(this); return false; } else { - // todo: error if stack contains something not dd, dt, li, optgroup, option, p, rp, rt, tbody, td, tfoot, th, thead, tr, body, html - anyOtherEndTag(t, tb); + if (tb.onStackNot(InBodyEndOtherErrors)) + tb.error(this); tb.transition(AfterBody); } break; case "html": - boolean notIgnored = tb.processEndTag("body"); - if (notIgnored) - return tb.process(endTag); - break; + if (!tb.onStack("body")) { + tb.error(this); + return false; // ignore + } else { + if (tb.onStackNot(InBodyEndOtherErrors)) + tb.error(this); + tb.transition(AfterBody); + return tb.process(t); // re-process + } + case "form": if (!tb.onStack("template")) { Element currentForm = tb.getFormElement(); @@ -1594,7 +1601,12 @@ enum HtmlTreeBuilderState { AfterBody { boolean process(Token t, HtmlTreeBuilder tb) { if (isWhitespace(t)) { - tb.insert(t.asCharacter()); // out of spec - include whitespace. spec would move into body + // spec deviation - currently body is still on stack, but we want this to go to the html node + Element html = tb.getFromStack("html"); + if (html != null) + tb.insert(t.asCharacter(), html); + else + tb.process(t, InBody); // will get into body } else if (t.isComment()) { tb.insert(t.asComment()); // into html node } else if (t.isDoctype()) { @@ -1607,7 +1619,6 @@ enum HtmlTreeBuilderState { tb.error(this); return false; } else { - if (tb.onStack("html")) tb.popStackToClose("html"); tb.transition(AfterAfterBody); } } else if (t.isEOF()) { @@ -1699,7 +1710,9 @@ enum HtmlTreeBuilderState { } else if (t.isDoctype() || (t.isStartTag() && t.asStartTag().normalName().equals("html"))) { return tb.process(t, InBody); } else if (isWhitespace(t)) { - tb.insert(t.asCharacter()); + // spec deviation - body and html still on stack, but want this space to go after </html> + Element doc = tb.getDocument(); + tb.insert(t.asCharacter(), doc); }else if (t.isEOF()) { // nice work chuck } else { @@ -1786,6 +1799,7 @@ enum HtmlTreeBuilderState { static final String[] InBodyEndClosers = new String[]{"address", "article", "aside", "blockquote", "button", "center", "details", "dir", "div", "dl", "fieldset", "figcaption", "figure", "footer", "header", "hgroup", "listing", "menu", "nav", "ol", "pre", "section", "summary", "ul"}; + static final String[] InBodyEndOtherErrors = new String[] {"body", "dd", "dt", "html", "li", "optgroup", "option", "p", "rb", "rp", "rt", "rtc", "tbody", "td", "tfoot", "th", "thead", "tr"}; static final String[] InBodyEndAdoptionFormatters = new String[]{"a", "b", "big", "code", "em", "font", "i", "nobr", "s", "small", "strike", "strong", "tt", "u"}; static final String[] InBodyEndTableFosters = new String[]{"table", "tbody", "tfoot", "thead", "tr"}; static final String[] InTableToBody = new String[]{"tbody", "tfoot", "thead"}; diff --git a/src/main/java/org/jsoup/parser/Tag.java b/src/main/java/org/jsoup/parser/Tag.java index 366bc63..97ed500 100644 --- a/src/main/java/org/jsoup/parser/Tag.java +++ b/src/main/java/org/jsoup/parser/Tag.java @@ -246,7 +246,8 @@ public class Tag implements Cloneable { "sub", "sup", "bdo", "iframe", "embed", "span", "input", "select", "textarea", "label", "button", "optgroup", "option", "legend", "datalist", "keygen", "output", "progress", "meter", "area", "param", "source", "track", "summary", "command", "device", "area", "basefont", "bgsound", "menuitem", "param", "source", "track", - "data", "bdi", "s", "strike", "nobr" + "data", "bdi", "s", "strike", "nobr", + "rb" // deprecated but still known / special handling }; private static final String[] emptyTags = { "meta", "link", "base", "frame", "img", "br", "wbr", "embed", "hr", "input", "keygen", "col", "command", diff --git a/src/test/java/org/jsoup/parser/HtmlParserTest.java b/src/test/java/org/jsoup/parser/HtmlParserTest.java index 26b546d..43475ce 100644 --- a/src/test/java/org/jsoup/parser/HtmlParserTest.java +++ b/src/test/java/org/jsoup/parser/HtmlParserTest.java @@ -1698,11 +1698,38 @@ public class HtmlParserTest { parser.setTrackErrors(10); Document doc = Jsoup.parse(html, parser); ParseErrorList errors = parser.getErrors(); - assertEquals(1, errors.size()); + assertEquals(2, errors.size()); Element ruby = doc.expectFirst("ruby"); assertEquals( "<ruby><div><rp>Hello</rp></div></ruby>", TextUtil.stripNewlines(ruby.outerHtml())); assertEquals("<1:16>: Unexpected StartTag token [<rp>] when in state [InBody]", errors.get(0).toString()); } + + @Test void errorOnEofIfOpen() { + String html = "<div>"; + Parser parser = Parser.htmlParser(); + parser.setTrackErrors(10); + Document doc = Jsoup.parse(html, parser); + ParseErrorList errors = parser.getErrors(); + assertEquals(1, errors.size()); + assertEquals("Unexpected EOF token [] when in state [InBody]", errors.get(0).getErrorMessage()); + } + + @Test void NoErrorOnEofIfBodyOpen() { + String html = "<body>"; + Parser parser = Parser.htmlParser(); + parser.setTrackErrors(10); + Document doc = Jsoup.parse(html, parser); + ParseErrorList errors = parser.getErrors(); + assertEquals(0, errors.size()); + } + + @Test void htmlClose() { + // https://github.com/jhy/jsoup/issues/1851 + String html = "<body><div>One</html>Two</div></body>"; + Document doc = Jsoup.parse(html); + //assertEquals("OneTwo", doc.expectFirst("body > div").text()); + System.out.println(doc.html()); + } } diff --git a/src/test/java/org/jsoup/parser/HtmlTreeBuilderStateTest.java b/src/test/java/org/jsoup/parser/HtmlTreeBuilderStateTest.java index c2dbfe3..55b828e 100644 --- a/src/test/java/org/jsoup/parser/HtmlTreeBuilderStateTest.java +++ b/src/test/java/org/jsoup/parser/HtmlTreeBuilderStateTest.java @@ -45,7 +45,7 @@ public class HtmlTreeBuilderStateTest { public void ensureArraysAreSorted() { List<Object[]> constants = findConstantArrays(Constants.class); ensureSorted(constants); - assertEquals(38, constants.size()); + assertEquals(39, constants.size()); } @Test public void ensureTagSearchesAreKnownTags() {
https://github.com/jhy/jsoup.gitdiff --git a/src/main/java/org/jsoup/parser/HtmlTreeBuilder.java b/src/main/java/org/jsoup/parser/HtmlTreeBuilder.java
gitbug-java_data_jhy-jsoup.json_16
diff --git a/src/main/java/org/jsoup/parser/HtmlTreeBuilder.java b/src/main/java/org/jsoup/parser/HtmlTreeBuilder.java index 9de525b..06e9c74 100644 --- a/src/main/java/org/jsoup/parser/HtmlTreeBuilder.java +++ b/src/main/java/org/jsoup/parser/HtmlTreeBuilder.java @@ -53,7 +53,7 @@ public class HtmlTreeBuilder extends TreeBuilder { private @Nullable Element contextElement; // fragment parse context -- could be null even if fragment parsing private ArrayList<Element> formattingElements; // active (open) formatting elements private ArrayList<HtmlTreeBuilderState> tmplInsertMode; // stack of Template Insertion modes - private List<String> pendingTableCharacters; // chars in table to be shifted out + private List<Token.Character> pendingTableCharacters; // chars in table to be shifted out private Token.EndTag emptyEnd; // reused empty end tag private boolean framesetOk; // if ok to go into frameset @@ -676,14 +676,20 @@ public class HtmlTreeBuilder extends TreeBuilder { this.formElement = formElement; } - void newPendingTableCharacters() { + void resetPendingTableCharacters() { pendingTableCharacters = new ArrayList<>(); } - List<String> getPendingTableCharacters() { + List<Token.Character> getPendingTableCharacters() { return pendingTableCharacters; } + void addPendingTableCharacters(Token.Character c) { + // make a clone of the token to maintain its state (as Tokens are otherwise reset) + Token.Character clone = c.clone(); + pendingTableCharacters.add(clone); + } + /** 13.2.6.3 Closing elements that have implied end tags When the steps below require the UA to generate implied end tags, then, while the current node is a dd element, a dt element, an li element, an optgroup element, an option element, a p element, an rb element, an rp element, an rt element, or an rtc element, the UA must pop the current node off the stack of open elements. diff --git a/src/main/java/org/jsoup/parser/HtmlTreeBuilderState.java b/src/main/java/org/jsoup/parser/HtmlTreeBuilderState.java index 99edf8c..3c5352e 100644 --- a/src/main/java/org/jsoup/parser/HtmlTreeBuilderState.java +++ b/src/main/java/org/jsoup/parser/HtmlTreeBuilderState.java @@ -6,7 +6,6 @@ import org.jsoup.nodes.Attributes; import org.jsoup.nodes.Document; import org.jsoup.nodes.DocumentType; import org.jsoup.nodes.Element; -import org.jsoup.nodes.Node; import java.util.ArrayList; @@ -995,7 +994,7 @@ enum HtmlTreeBuilderState { InTable { boolean process(Token t, HtmlTreeBuilder tb) { if (t.isCharacter() && inSorted(tb.currentElement().normalName(), InTableFoster)) { - tb.newPendingTableCharacters(); + tb.resetPendingTableCharacters(); tb.markInsertionMode(); tb.transition(InTableText); return tb.process(t); @@ -1106,25 +1105,25 @@ enum HtmlTreeBuilderState { tb.error(this); return false; } else { - tb.getPendingTableCharacters().add(c.getData()); + tb.addPendingTableCharacters(c); } - } else {// todo - don't really like the way these table character data lists are built + } else { if (tb.getPendingTableCharacters().size() > 0) { - for (String character : tb.getPendingTableCharacters()) { - if (!isWhitespace(character)) { + for (Token.Character c : tb.getPendingTableCharacters()) { + if (!isWhitespace(c)) { // InTable anything else section: tb.error(this); if (inSorted(tb.currentElement().normalName(), InTableFoster)) { tb.setFosterInserts(true); - tb.process(new Token.Character().data(character), InBody); + tb.process(c, InBody); tb.setFosterInserts(false); } else { - tb.process(new Token.Character().data(character), InBody); + tb.process(c, InBody); } } else - tb.insert(new Token.Character().data(character)); + tb.insert(c); } - tb.newPendingTableCharacters(); + tb.resetPendingTableCharacters(); } tb.transition(tb.originalState()); return tb.process(t); @@ -1759,10 +1758,6 @@ enum HtmlTreeBuilderState { return false; } - private static boolean isWhitespace(String data) { - return StringUtil.isBlank(data); - } - private static void handleRcData(Token.StartTag startTag, HtmlTreeBuilder tb) { tb.tokeniser.transition(TokeniserState.Rcdata); tb.markInsertionMode(); diff --git a/src/main/java/org/jsoup/parser/Token.java b/src/main/java/org/jsoup/parser/Token.java index 819b8ae..b0fc0af 100644 --- a/src/main/java/org/jsoup/parser/Token.java +++ b/src/main/java/org/jsoup/parser/Token.java @@ -382,7 +382,7 @@ abstract class Token { } } - static class Character extends Token { + static class Character extends Token implements Cloneable { private String data; Character() { @@ -410,6 +410,14 @@ abstract class Token { public String toString() { return getData(); } + + @Override protected Token.Character clone() { + try { + return (Token.Character) super.clone(); + } catch (CloneNotSupportedException e) { + throw new RuntimeException(e); + } + } } final static class CData extends Character { diff --git a/src/test/java/org/jsoup/nodes/PositionTest.java b/src/test/java/org/jsoup/nodes/PositionTest.java index 813ed9b..78df6fb 100644 --- a/src/test/java/org/jsoup/nodes/PositionTest.java +++ b/src/test/java/org/jsoup/nodes/PositionTest.java @@ -3,9 +3,12 @@ package org.jsoup.nodes; import org.jsoup.Jsoup; import org.jsoup.integration.servlets.FileServlet; import org.jsoup.parser.Parser; +import org.jsoup.select.NodeTraversor; import org.junit.jupiter.api.Test; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import static org.junit.jupiter.api.Assertions.*; @@ -169,4 +172,23 @@ class PositionTest { assertEquals("17,5:779-17,12:786", item.endSourceRange().toString()); } + @Test void tracksTableMovedText() { + String html = "<table>foo<tr>bar<td>baz</td>qux</tr>coo</table>"; + Document doc = Jsoup.parse(html, TrackingParser); + + List<TextNode> textNodes = new ArrayList<>(); + NodeTraversor.traverse((Node node, int depth) -> { + if (node instanceof TextNode) { + textNodes.add((TextNode) node); + } + }, doc); + + assertEquals(5, textNodes.size()); + assertEquals("1,8:7-1,11:10", textNodes.get(0).sourceRange().toString()); + assertEquals("1,15:14-1,18:17", textNodes.get(1).sourceRange().toString()); + assertEquals("1,22:21-1,25:24", textNodes.get(2).sourceRange().toString()); + assertEquals("1,30:29-1,33:32", textNodes.get(3).sourceRange().toString()); + assertEquals("1,38:37-1,41:40", textNodes.get(4).sourceRange().toString()); + } + } \ No newline at end of file
https://github.com/jhy/jsoup.gitdiff --git a/src/main/java/org/jsoup/parser/HtmlTreeBuilder.java b/src/main/java/org/jsoup/parser/HtmlTreeBuilder.java
gitbug-java_data_jhy-jsoup.json_17
diff --git a/src/main/java/org/jsoup/parser/CharacterReader.java b/src/main/java/org/jsoup/parser/CharacterReader.java index df902b1..1d00ec6 100644 --- a/src/main/java/org/jsoup/parser/CharacterReader.java +++ b/src/main/java/org/jsoup/parser/CharacterReader.java @@ -116,6 +116,11 @@ public final class CharacterReader { return readerPos + bufPos; } + /** Tests if the buffer has been fully read. */ + boolean readFully() { + return readFully; + } + /** Enables or disables line number tracking. By default, will be <b>off</b>.Tracking line numbers improves the legibility of parser error messages, for example. Tracking should be enabled before any content is read to be of diff --git a/src/main/java/org/jsoup/parser/TokeniserState.java b/src/main/java/org/jsoup/parser/TokeniserState.java index 874fed0..f269fc6 100644 --- a/src/main/java/org/jsoup/parser/TokeniserState.java +++ b/src/main/java/org/jsoup/parser/TokeniserState.java @@ -186,7 +186,7 @@ enum TokeniserState { if (r.matches('/')) { t.createTempBuffer(); t.advanceTransition(RCDATAEndTagOpen); - } else if (r.matchesAsciiAlpha() && t.appropriateEndTagName() != null && !r.containsIgnoreCase(t.appropriateEndTagSeq())) { + } else if (r.readFully() && r.matchesAsciiAlpha() && t.appropriateEndTagName() != null && !r.containsIgnoreCase(t.appropriateEndTagSeq())) { // diverge from spec: got a start tag, but there's no appropriate end tag (</title>), so rather than // consuming to EOF; break out here t.tagPending = t.createTagPending(false).name(t.appropriateEndTagName()); diff --git a/src/test/java/org/jsoup/parser/HtmlParserTest.java b/src/test/java/org/jsoup/parser/HtmlParserTest.java index 43475ce..55f5065 100644 --- a/src/test/java/org/jsoup/parser/HtmlParserTest.java +++ b/src/test/java/org/jsoup/parser/HtmlParserTest.java @@ -1732,4 +1732,20 @@ public class HtmlParserTest { //assertEquals("OneTwo", doc.expectFirst("body > div").text()); System.out.println(doc.html()); } + + @Test void largeTextareaContents() { + // https://github.com/jhy/jsoup/issues/1929 + StringBuilder sb = new StringBuilder(); + int num = 2000; + for (int i = 0; i <= num; i++) { + sb.append("\n<text>foo</text>\n"); + } + String textContent = sb.toString(); + String sourceHtml = "<textarea>" + textContent + "</textarea>"; + + Document doc = Jsoup.parse(sourceHtml); + Element textArea = doc.expectFirst("textarea"); + + assertEquals(textContent, textArea.wholeText()); + } }
https://github.com/jhy/jsoup.gitdiff --git a/src/main/java/org/jsoup/parser/CharacterReader.java b/src/main/java/org/jsoup/parser/CharacterReader.java
gitbug-java_data_jhy-jsoup.json_18
diff --git a/src/main/java/org/jsoup/nodes/Element.java b/src/main/java/org/jsoup/nodes/Element.java index 8b27637..05ee2e7 100644 --- a/src/main/java/org/jsoup/nodes/Element.java +++ b/src/main/java/org/jsoup/nodes/Element.java @@ -1844,7 +1844,7 @@ public class Element extends Node { } private boolean isFormatAsBlock(Document.OutputSettings out) { - return tag.formatAsBlock() || (parent() != null && parent().tag().formatAsBlock()) || out.outline(); + return tag.isBlock() || (parent() != null && parent().tag().formatAsBlock()) || out.outline(); } private boolean isInlineable(Document.OutputSettings out) { diff --git a/src/test/java/org/jsoup/nodes/ElementTest.java b/src/test/java/org/jsoup/nodes/ElementTest.java index 0bb433c..5ff3041 100644 --- a/src/test/java/org/jsoup/nodes/ElementTest.java +++ b/src/test/java/org/jsoup/nodes/ElementTest.java @@ -2701,4 +2701,28 @@ public class ElementTest { Document doc = Jsoup.parse(html); assertEquals(html, doc.body().html()); } + + @Test void nestedFormatAsInlinePrintsAsBlock() { + // https://github.com/jhy/jsoup/issues/1926 + String h = " <table>\n" + + " <tr>\n" + + " <td>\n" + + " <p style=\"display:inline;\">A</p>\n" + + " <p style=\"display:inline;\">B</p>\n" + + " </td>\n" + + " </tr>\n" + + " </table>"; + Document doc = Jsoup.parse(h); + String out = doc.body().html(); + assertEquals("<table>\n" + + " <tbody>\n" + + " <tr>\n" + + " <td>\n" + + " <p style=\"display:inline;\">A</p>\n" + + " <p style=\"display:inline;\">B</p></td>\n" + + " </tr>\n" + + " </tbody>\n" + + "</table>", out); + // todo - I would prefer the </td> to wrap down there - but need to reimplement pretty printer to simplify and track indented state + } } diff --git a/src/test/java/org/jsoup/parser/HtmlParserTest.java b/src/test/java/org/jsoup/parser/HtmlParserTest.java index 383f677..e7f5c23 100644 --- a/src/test/java/org/jsoup/parser/HtmlParserTest.java +++ b/src/test/java/org/jsoup/parser/HtmlParserTest.java @@ -720,15 +720,8 @@ public class HtmlParserTest { // and the <i> inside the table and does not leak out. String h = "<p><b>One</p> <table><tr><td><p><i>Three<p>Four</i></td></tr></table> <p>Five</p>"; Document doc = Jsoup.parse(h); - String want = "<p><b>One</b></p><b>\n" + - " <table>\n" + - " <tbody>\n" + - " <tr>\n" + - " <td><p><i>Three</i></p><p><i>Four</i></p></td>\n" + - " </tr>\n" + - " </tbody>\n" + - " </table><p>Five</p></b>"; - assertEquals(want, doc.body().html()); + String want = "<p><b>One</b></p><b><table><tbody><tr><td><p><i>Three</i></p><p><i>Four</i></p></td></tr></tbody></table><p>Five</p></b>"; + assertEquals(want, TextUtil.stripNewlines(doc.body().html())); } @Test public void commentBeforeHtml() { @@ -777,7 +770,7 @@ public class HtmlParserTest { Document two = Jsoup.parse("<title>One<b>Two <p>Test</p>"); // no title, so <b> causes </title> breakout assertEquals("One", two.title()); - assertEquals("<b>Two <p>Test</p></b>", two.body().html()); + assertEquals("<b>Two \n <p>Test</p></b>", two.body().html()); } @Test public void handlesUnclosedScriptAtEof() { @@ -1470,7 +1463,7 @@ public class HtmlParserTest { assertEquals(1, nodes.size()); Node node = nodes.get(0); assertEquals("h2", node.nodeName()); - assertEquals("<p><h2>text</h2></p>", node.parent().outerHtml()); + assertEquals("<p>\n <h2>text</h2></p>", node.parent().outerHtml()); } @Test public void nestedPFragments() { @@ -1479,7 +1472,7 @@ public class HtmlParserTest { List<Node> nodes = new Document("").parser().parseFragmentInput(bareFragment, new Element("p"), ""); assertEquals(2, nodes.size()); Node node = nodes.get(0); - assertEquals("<p><p></p><a></a></p>", node.parent().outerHtml()); // mis-nested because fragment forced into the element, OK + assertEquals("<p>\n <p></p><a></a></p>", node.parent().outerHtml()); // mis-nested because fragment forced into the element, OK } @Test public void nestedAnchorAdoption() {
https://github.com/jhy/jsoup.gitdiff --git a/src/main/java/org/jsoup/nodes/Element.java b/src/main/java/org/jsoup/nodes/Element.java
gitbug-java_data_jhy-jsoup.json_19
diff --git a/src/main/java/org/jsoup/helper/W3CDom.java b/src/main/java/org/jsoup/helper/W3CDom.java index 8caf31f..29296b1 100644 --- a/src/main/java/org/jsoup/helper/W3CDom.java +++ b/src/main/java/org/jsoup/helper/W3CDom.java @@ -3,6 +3,7 @@ package org.jsoup.helper; import org.jsoup.internal.StringUtil; import org.jsoup.nodes.Attribute; import org.jsoup.nodes.Attributes; +import org.jsoup.parser.HtmlTreeBuilder; import org.jsoup.select.NodeTraversor; import org.jsoup.select.NodeVisitor; import org.jsoup.select.Selector; @@ -77,6 +78,8 @@ public class W3CDom { /** Update the namespace aware setting. This impacts the factory that is used to create W3C nodes from jsoup nodes. + <p>For HTML documents, controls if the document will be in the default {@code http://www.w3.org/1999/xhtml} + namespace if otherwise unset.</p>. @param namespaceAware the updated setting @return this W3CDom, for chaining. */ @@ -337,6 +340,7 @@ public class W3CDom { protected static class W3CBuilder implements NodeVisitor { private static final String xmlnsKey = "xmlns"; private static final String xmlnsPrefix = "xmlns:"; + private static final String xhtmlNs = "http://www.w3.org/1999/xhtml"; private final Document doc; private boolean namespaceAware = true; @@ -350,7 +354,12 @@ public class W3CDom { namespacesStack.push(new HashMap<>()); dest = doc; contextElement = (org.jsoup.nodes.Element) doc.getUserData(ContextProperty); // Track the context jsoup Element, so we can save the corresponding w3c element - } + final org.jsoup.nodes.Document inDoc = contextElement.ownerDocument(); + if (namespaceAware && inDoc != null && inDoc.parser().getTreeBuilder() instanceof HtmlTreeBuilder) { + // as per the WHATWG HTML5 spec § 2.1.3, elements are in the HTML namespace by default + namespacesStack.peek().put("", xhtmlNs); + } + } public void head(org.jsoup.nodes.Node source, int depth) { namespacesStack.push(new HashMap<>(namespacesStack.peek())); // inherit from above on the stack @@ -366,9 +375,9 @@ public class W3CDom { tagname to something safe, because that isn't going to be meaningful downstream. This seems(?) to be how browsers handle the situation, also. https://github.com/jhy/jsoup/issues/1093 */ try { - Element el = namespace == null && tagName.contains(":") ? - doc.createElementNS("", tagName) : // doesn't have a real namespace defined - doc.createElementNS(namespace, tagName); + // use an empty namespace if none is present but the tag name has a prefix + String imputedNamespace = namespace == null && tagName.contains(":") ? "" : namespace; + Element el = doc.createElementNS(imputedNamespace, tagName); copyAttributes(sourceEl, el); append(el, sourceEl); if (sourceEl == contextElement) diff --git a/src/test/java/org/jsoup/helper/W3CDomTest.java b/src/test/java/org/jsoup/helper/W3CDomTest.java index f89832a..c1daeb5 100644 --- a/src/test/java/org/jsoup/helper/W3CDomTest.java +++ b/src/test/java/org/jsoup/helper/W3CDomTest.java @@ -7,7 +7,6 @@ import org.jsoup.nodes.Element; import org.jsoup.nodes.TextNode; import org.junit.jupiter.api.Test; import org.w3c.dom.Document; -import org.w3c.dom.DocumentType; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.InputSource; @@ -62,7 +61,7 @@ public class W3CDomTest { assertEquals(0, meta.getLength()); String out = W3CDom.asString(wDoc, W3CDom.OutputXml()); - String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><html><head><title>W3c</title></head><body><p class=\"one\" id=\"12\">Text</p><!-- comment --><invalid>What<script>alert('!')</script></invalid></body></html>"; + String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title>W3c</title></head><body><p class=\"one\" id=\"12\">Text</p><!-- comment --><invalid>What<script>alert('!')</script></invalid></body></html>"; assertEquals(expected, TextUtil.stripNewlines(out)); Document roundTrip = parseXml(out, true); @@ -74,7 +73,7 @@ public class W3CDomTest { String furtherOut = W3CDom.asString(wDoc, properties); assertTrue(furtherOut.length() > out.length()); // wanted to assert formatting, but actual indentation is platform specific so breaks in CI String furtherExpected = - "<?xml version=\"1.0\" encoding=\"UTF-8\"?><html><head><title>W3c</title></head><body><p class=\"one\" id=\"12\">Text</p><!-- comment --><invalid>What<script>alert('!')</script></invalid></body></html>"; + "<?xml version=\"1.0\" encoding=\"UTF-8\"?><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title>W3c</title></head><body><p class=\"one\" id=\"12\">Text</p><!-- comment --><invalid>What<script>alert('!')</script></invalid></body></html>"; assertEquals(furtherExpected, TextUtil.stripNewlines(furtherOut)); // on windows, DOM will write newlines as \r\n } @@ -151,7 +150,7 @@ public class W3CDomTest { Document w3Doc = W3CDom.convert(jsoupDoc); String xml = W3CDom.asString(w3Doc, W3CDom.OutputXml()); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><html><head/><body name=\"\" style=\"color: red\"/></html>", xml); + assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><html xmlns=\"http://www.w3.org/1999/xhtml\"><head/><body name=\"\" style=\"color: red\"/></html>", xml); } @Test @@ -162,7 +161,7 @@ public class W3CDomTest { Document w3Doc = W3CDom.convert(jsoupDoc); String out = W3CDom.asString(w3Doc, W3CDom.OutputHtml()); - String expected = "<!DOCTYPE html SYSTEM \"about:legacy-compat\"><html><head><META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></head><body><p hành=\"1\" hình=\"2\">unicode attr names</p></body></html>"; + String expected = "<!DOCTYPE html SYSTEM \"about:legacy-compat\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></head><body><p hành=\"1\" hình=\"2\">unicode attr names</p></body></html>"; assertEquals(expected, TextUtil.stripNewlines(out)); } @@ -175,7 +174,7 @@ public class W3CDomTest { Document w3Doc = W3CDom.convert(jsoupDoc); String out = W3CDom.asString(w3Doc, W3CDom.OutputHtml()); - String expected = "<!DOCTYPE html SYSTEM \"about:legacy-compat\"><html><head><META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></head><body><p hnh=\"2\">unicode attr names coerced</p></body></html>"; + String expected = "<!DOCTYPE html SYSTEM \"about:legacy-compat\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></head><body><p hnh=\"2\">unicode attr names coerced</p></body></html>"; assertEquals(expected, TextUtil.stripNewlines(out)); } @@ -185,7 +184,7 @@ public class W3CDomTest { Document w3Doc = W3CDom.convert(jsoup); String xml = W3CDom.asString(w3Doc, W3CDom.OutputXml()); - assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><html><head/><body>&lt;インセンティブで高収入!&gt;Text <p>More</p></body></html>", xml); + assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><html xmlns=\"http://www.w3.org/1999/xhtml\"><head/><body>&lt;インセンティブで高収入!&gt;Text <p>More</p></body></html>", xml); } @Test @@ -196,7 +195,7 @@ public class W3CDomTest { Document w3Doc = new W3CDom().fromJsoup(doc); Node htmlEl = w3Doc.getFirstChild(); - assertNull(htmlEl.getNamespaceURI()); + assertEquals("http://www.w3.org/1999/xhtml", htmlEl.getNamespaceURI()); assertEquals("html", htmlEl.getLocalName()); assertEquals("html", htmlEl.getNodeName()); @@ -211,7 +210,7 @@ public class W3CDomTest { W3CDom w3c = new W3CDom(); String html = "<html><body><div>hello</div></body></html>"; Document dom = w3c.fromJsoup(Jsoup.parse(html)); - NodeList nodeList = xpath(dom, "//body");// no ns, so needs no prefix + NodeList nodeList = xpath(dom, "//*[local-name()=\"body\"]");// namespace aware; HTML namespace is default assertEquals("div", nodeList.item(0).getLocalName()); // default output is namespace aware, so query needs to be as well @@ -243,6 +242,17 @@ public class W3CDomTest { } @Test + public void xhtmlNoNamespace() throws XPathExpressionException { + W3CDom w3c = new W3CDom(); + String html = "<html><body><div>hello</div></body></html>"; + w3c.namespaceAware(false); + Document dom = w3c.fromJsoup(Jsoup.parse(html)); + NodeList nodeList = xpath(dom, "//body");// no namespace + assertEquals(1, nodeList.getLength()); + assertEquals("div", nodeList.item(0).getLocalName()); + } + + @Test void canDisableNamespaces() throws XPathExpressionException { W3CDom w3c = new W3CDom(); assertTrue(w3c.namespaceAware()); @@ -266,26 +276,25 @@ public class W3CDomTest { // TODO - not super happy with this output - but plain DOM doesn't let it out, and don't want to rebuild the writer // because we have Saxon on the test classpath, the transformer will change to that, and so case may change (e.g. Java base in META, Saxon is meta for HTML) String base = "<!DOCTYPE html><p>One</p>"; - assertEqualsIgnoreCase("<!DOCTYPE html SYSTEM \"about:legacy-compat\"><html><head><META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></head><body><p>One</p></body></html>", - output(base, true)); - assertEqualsIgnoreCase("<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE html SYSTEM \"about:legacy-compat\"><html><head/><body><p>One</p></body></html>", output(base, false)); + assertEqualsIgnoreCase("<!DOCTYPE html SYSTEM \"about:legacy-compat\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></head><body><p>One</p></body></html>", output(base, true)); + assertEqualsIgnoreCase("<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE html SYSTEM \"about:legacy-compat\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head/><body><p>One</p></body></html>", output(base, false)); String publicDoc = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"; - assertEqualsIgnoreCase("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html><head><META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></head><body></body></html>", output(publicDoc, true)); + assertEqualsIgnoreCase("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></head><body></body></html>", output(publicDoc, true)); // different impls will have different XML formatting. OpenJDK 13 default gives this: <body /> but others have <body/>, so just check start assertTrue(output(publicDoc, false).startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE html PUBLIC")); String systemDoc = "<!DOCTYPE html SYSTEM \"exampledtdfile.dtd\">"; - assertEqualsIgnoreCase("<!DOCTYPE html SYSTEM \"exampledtdfile.dtd\"><html><head><META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></head><body></body></html>", output(systemDoc, true)); - assertEqualsIgnoreCase("<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE html SYSTEM \"exampledtdfile.dtd\"><html><head/><body/></html>", output(systemDoc, false)); + assertEqualsIgnoreCase("<!DOCTYPE html SYSTEM \"exampledtdfile.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></head><body></body></html>", output(systemDoc, true)); + assertEqualsIgnoreCase("<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE html SYSTEM \"exampledtdfile.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head/><body/></html>", output(systemDoc, false)); String legacyDoc = "<!DOCTYPE html SYSTEM \"about:legacy-compat\">"; - assertEqualsIgnoreCase("<!DOCTYPE html SYSTEM \"about:legacy-compat\"><html><head><META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></head><body></body></html>", output(legacyDoc, true)); - assertEqualsIgnoreCase("<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE html SYSTEM \"about:legacy-compat\"><html><head/><body/></html>", output(legacyDoc, false)); + assertEqualsIgnoreCase("<!DOCTYPE html SYSTEM \"about:legacy-compat\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></head><body></body></html>", output(legacyDoc, true)); + assertEqualsIgnoreCase("<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE html SYSTEM \"about:legacy-compat\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head/><body/></html>", output(legacyDoc, false)); String noDoctype = "<p>One</p>"; - assertEqualsIgnoreCase("<html><head><META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></head><body><p>One</p></body></html>", output(noDoctype, true)); - assertEqualsIgnoreCase("<?xml version=\"1.0\" encoding=\"UTF-8\"?><html><head/><body><p>One</p></body></html>", output(noDoctype, false)); + assertEqualsIgnoreCase("<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></head><body><p>One</p></body></html>", output(noDoctype, true)); + assertEqualsIgnoreCase("<?xml version=\"1.0\" encoding=\"UTF-8\"?><html xmlns=\"http://www.w3.org/1999/xhtml\"><head/><body><p>One</p></body></html>", output(noDoctype, false)); } private String output(String in, boolean modeHtml) { @@ -300,6 +309,24 @@ public class W3CDomTest { assertEquals(want.toLowerCase(Locale.ROOT), have.toLowerCase(Locale.ROOT)); } + + @Test + public void canOutputHtmlWithoutNamespace() { + String html = "<p>One</p>"; + org.jsoup.nodes.Document jdoc = Jsoup.parse(html); + W3CDom w3c = new W3CDom(); + w3c.namespaceAware(false); + + String asHtml = W3CDom.asString(w3c.fromJsoup(jdoc), W3CDom.OutputHtml()); + String asXtml = W3CDom.asString(w3c.fromJsoup(jdoc), W3CDom.OutputXml()); + assertEqualsIgnoreCase( + "<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"></head><body><p>one</p></body></html>", + asHtml); + assertEqualsIgnoreCase( + "<?xml version=\"1.0\" encoding=\"UTF-8\"?><html><head/><body><p>One</p></body></html>", + asXtml); + } + @Test public void convertsElementsAndMaintainsSource() { org.jsoup.nodes.Document jdoc = Jsoup.parse("<body><div><p>One</div><div><p>Two"); W3CDom w3CDom = new W3CDom();
https://github.com/jhy/jsoup.gitdiff --git a/src/main/java/org/jsoup/helper/W3CDom.java b/src/main/java/org/jsoup/helper/W3CDom.java
gitbug-java_data_jhy-jsoup.json_20
diff --git a/src/main/java/org/jsoup/parser/HtmlTreeBuilder.java b/src/main/java/org/jsoup/parser/HtmlTreeBuilder.java index 06e9c74..be0498c 100644 --- a/src/main/java/org/jsoup/parser/HtmlTreeBuilder.java +++ b/src/main/java/org/jsoup/parser/HtmlTreeBuilder.java @@ -10,6 +10,7 @@ import org.jsoup.nodes.Element; import org.jsoup.nodes.FormElement; import org.jsoup.nodes.Node; import org.jsoup.nodes.TextNode; +import org.jsoup.parser.Token.StartTag; import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; @@ -227,13 +228,7 @@ public class HtmlTreeBuilder extends TreeBuilder { } Element insert(final Token.StartTag startTag) { - // cleanup duplicate attributes: - if (startTag.hasAttributes() && !startTag.attributes.isEmpty()) { - int dupes = startTag.attributes.deduplicate(settings); - if (dupes > 0) { - error("Dropped duplicate attribute(s) in tag [%s]", startTag.normalName); - } - } + dedupeAttributes(startTag); // handle empty unknown tags // when the spec expects an empty tag, will directly hit insertEmpty, so won't generate this fake end tag. @@ -250,7 +245,7 @@ public class HtmlTreeBuilder extends TreeBuilder { return el; } - Element insertStartTag(String startTagName) { + Element insertStartTag(String startTagName) { Element el = new Element(tagFor(startTagName, settings), null); insert(el); return el; @@ -267,6 +262,8 @@ public class HtmlTreeBuilder extends TreeBuilder { } Element insertEmpty(Token.StartTag startTag) { + dedupeAttributes(startTag); + Tag tag = tagFor(startTag.name(), settings); Element el = new Element(tag, null, settings.normalizeAttributes(startTag.attributes)); insertNode(el, startTag); @@ -282,6 +279,8 @@ public class HtmlTreeBuilder extends TreeBuilder { } FormElement insertForm(Token.StartTag startTag, boolean onStack, boolean checkTemplateStack) { + dedupeAttributes(startTag); + Tag tag = tagFor(startTag.name(), settings); FormElement el = new FormElement(tag, null, settings.normalizeAttributes(startTag.attributes)); if (checkTemplateStack) { @@ -340,6 +339,16 @@ public class HtmlTreeBuilder extends TreeBuilder { onNodeInserted(node, token); } + /** Cleanup duplicate attributes. **/ + private void dedupeAttributes(StartTag startTag) { + if (startTag.hasAttributes() && !startTag.attributes.isEmpty()) { + int dupes = startTag.attributes.deduplicate(settings); + if (dupes > 0) { + error("Dropped duplicate attribute(s) in tag [%s]", startTag.normalName); + } + } + } + Element pop() { int size = stack.size(); return stack.remove(size-1); diff --git a/src/test/java/org/jsoup/parser/HtmlParserTest.java b/src/test/java/org/jsoup/parser/HtmlParserTest.java index e7f5c23..4172d0f 100644 --- a/src/test/java/org/jsoup/parser/HtmlParserTest.java +++ b/src/test/java/org/jsoup/parser/HtmlParserTest.java @@ -7,13 +7,16 @@ import org.jsoup.internal.StringUtil; import org.jsoup.nodes.*; import org.jsoup.safety.Safelist; import org.jsoup.select.Elements; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; import java.util.List; +import java.util.stream.Stream; import static org.jsoup.parser.ParseSettings.preserveCase; import static org.junit.jupiter.api.Assertions.*; @@ -46,16 +49,25 @@ public class HtmlParserTest { assertEquals("foo > bar", p.attr("class")); } - @Test public void dropsDuplicateAttributes() { - String html = "<p One=One ONE=Two Two=two one=Three One=Four two=Five>Text</p>"; + @ParameterizedTest @MethodSource("dupeAttributeData") + public void dropsDuplicateAttributes(String html, String expected) { Parser parser = Parser.htmlParser().setTrackErrors(10); Document doc = parser.parseInput(html, ""); - Element p = doc.selectFirst("p"); - assertEquals("<p one=\"One\" two=\"two\">Text</p>", p.outerHtml()); // normalized names due to lower casing + Element el = doc.expectFirst("body > *"); + assertEquals(expected, el.outerHtml()); // normalized names due to lower casing + String tag = el.normalName(); assertEquals(1, parser.getErrors().size()); - assertEquals("Dropped duplicate attribute(s) in tag [p]", parser.getErrors().get(0).getErrorMessage()); + assertEquals("Dropped duplicate attribute(s) in tag [" + tag + "]", parser.getErrors().get(0).getErrorMessage()); + } + + private static Stream<Arguments> dupeAttributeData() { + return Stream.of( + Arguments.of("<p One=One ONE=Two Two=two one=Three One=Four two=Five>Text</p>", "<p one=\"One\" two=\"two\">Text</p>"), + Arguments.of("<img One=One ONE=Two Two=two one=Three One=Four two=Five>", "<img one=\"One\" two=\"two\">"), + Arguments.of("<form One=One ONE=Two Two=two one=Three One=Four two=Five></form>", "<form one=\"One\" two=\"two\"></form>") + ); } @Test public void retainsAttributesOfDifferentCaseIfSensitive() {
https://github.com/jhy/jsoup.gitdiff --git a/src/main/java/org/jsoup/parser/HtmlTreeBuilder.java b/src/main/java/org/jsoup/parser/HtmlTreeBuilder.java
gitbug-java_data_jhy-jsoup.json_21
diff --git a/src/main/java/org/jsoup/helper/UrlBuilder.java b/src/main/java/org/jsoup/helper/UrlBuilder.java index 89f46a1..4deda36 100644 --- a/src/main/java/org/jsoup/helper/UrlBuilder.java +++ b/src/main/java/org/jsoup/helper/UrlBuilder.java @@ -38,24 +38,20 @@ final class UrlBuilder { u.getUserInfo(), IDN.toASCII(decodePart(u.getHost())), // puny-code u.getPort(), - decodePart(u.getPath()), - null, null // query and fragment appended later so as not to encode + null, null, null // path, query and fragment appended later so as not to encode ); - String normUrl = uri.toASCIIString(); - if (q != null || u.getRef() != null) { - StringBuilder sb = StringUtil.borrowBuilder().append(normUrl); - if (q != null) { - sb.append('?'); - appendToAscii(StringUtil.releaseBuilder(q), true, sb); - } - if (u.getRef() != null) { - sb.append('#'); - appendToAscii(u.getRef(), false, sb); - } - normUrl = StringUtil.releaseBuilder(sb); + StringBuilder normUrl = StringUtil.borrowBuilder().append(uri.toASCIIString()); + appendToAscii(u.getPath(), false, normUrl); + if (q != null) { + normUrl.append('?'); + appendToAscii(StringUtil.releaseBuilder(q), true, normUrl); } - u = new URL(normUrl); + if (u.getRef() != null) { + normUrl.append('#'); + appendToAscii(u.getRef(), false, normUrl); + } + u = new URL(StringUtil.releaseBuilder(normUrl)); return u; } catch (MalformedURLException | URISyntaxException | UnsupportedEncodingException e) { // we assert here so that any incomplete normalization issues can be caught in devel. but in practise, diff --git a/src/test/java/org/jsoup/helper/HttpConnectionTest.java b/src/test/java/org/jsoup/helper/HttpConnectionTest.java index 840d8a8..9834f72 100644 --- a/src/test/java/org/jsoup/helper/HttpConnectionTest.java +++ b/src/test/java/org/jsoup/helper/HttpConnectionTest.java @@ -255,13 +255,13 @@ public class HttpConnectionTest { } @Test public void encodeUrl() throws MalformedURLException { - URL url1 = new URL("https://test.com/foo bar/[One]?q=white space#frag"); + URL url1 = new URL("https://test.com/foo%20bar/%5BOne%5D?q=white+space#frag"); URL url2 = new UrlBuilder(url1).build(); assertEquals("https://test.com/foo%20bar/%5BOne%5D?q=white+space#frag", url2.toExternalForm()); } @Test void encodedUrlDoesntDoubleEncode() throws MalformedURLException { - URL url1 = new URL("https://test.com/foo bar/[One]?q=white space#frag ment"); + URL url1 = new URL("https://test.com/foo%20bar/%5BOne%5D?q=white+space#frag%20ment"); URL url2 = new UrlBuilder(url1).build(); URL url3 = new UrlBuilder(url2).build(); assertEquals("https://test.com/foo%20bar/%5BOne%5D?q=white+space#frag%20ment", url2.toExternalForm()); @@ -274,6 +274,20 @@ public class HttpConnectionTest { assertEquals("https://example.com/a%20b%20c?query+string", url.toExternalForm()); } + @Test void encodedUrlPathIsPreserved() { + // https://github.com/jhy/jsoup/issues/1952 + Connection connect = Jsoup.connect("https://example.com/%2B32"); + URL url = connect.request().url(); + assertEquals("https://example.com/%2B32", url.toExternalForm()); + } + + @Test void urlPathPlusIsPreserved() { + // https://github.com/jhy/jsoup/issues/1952 + Connection connect = Jsoup.connect("https://example.com/123+456"); + URL url = connect.request().url(); + assertEquals("https://example.com/123+456", url.toExternalForm()); + } + @Test public void noUrlThrowsValidationError() throws IOException { HttpConnection con = new HttpConnection(); boolean threw = false;
https://github.com/jhy/jsoup.gitdiff --git a/src/main/java/org/jsoup/helper/UrlBuilder.java b/src/main/java/org/jsoup/helper/UrlBuilder.java
gitbug-java_data_jhy-jsoup.json_22
diff --git a/src/main/java/org/jsoup/nodes/Document.java b/src/main/java/org/jsoup/nodes/Document.java index 70c571f..9930dc5 100644 --- a/src/main/java/org/jsoup/nodes/Document.java +++ b/src/main/java/org/jsoup/nodes/Document.java @@ -385,9 +385,9 @@ public class Document extends Element { public enum Syntax {html, xml} private Entities.EscapeMode escapeMode = Entities.EscapeMode.base; - private Charset charset = DataUtil.UTF_8; + private Charset charset; + Entities.CoreCharset coreCharset; // fast encoders for ascii and utf8 private final ThreadLocal<CharsetEncoder> encoderThreadLocal = new ThreadLocal<>(); // initialized by start of OuterHtmlVisitor - @Nullable Entities.CoreCharset coreCharset; // fast encoders for ascii and utf8 private boolean prettyPrint = true; private boolean outline = false; @@ -395,7 +395,9 @@ public class Document extends Element { private int maxPaddingWidth = 30; private Syntax syntax = Syntax.html; - public OutputSettings() {} + public OutputSettings() { + charset(DataUtil.UTF_8); + } /** * Get the document's current HTML escape mode: <code>base</code>, which provides a limited set of named HTML @@ -439,6 +441,7 @@ public class Document extends Element { */ public OutputSettings charset(Charset charset) { this.charset = charset; + coreCharset = Entities.CoreCharset.byName(charset.name()); return this; } @@ -456,7 +459,6 @@ public class Document extends Element { // created at start of OuterHtmlVisitor so each pass has own encoder, so OutputSettings can be shared among threads CharsetEncoder encoder = charset.newEncoder(); encoderThreadLocal.set(encoder); - coreCharset = Entities.CoreCharset.byName(encoder.charset().name()); return encoder; } @@ -570,7 +572,7 @@ public class Document extends Element { } catch (CloneNotSupportedException e) { throw new RuntimeException(e); } - clone.charset(charset.name()); // new charset and charset encoder + clone.charset(charset.name()); // new charset, coreCharset, and charset encoder clone.escapeMode = Entities.EscapeMode.valueOf(escapeMode.name()); // indentAmount, maxPaddingWidth, and prettyPrint are primitives so object.clone() will handle return clone; diff --git a/src/test/java/org/jsoup/nodes/EntitiesTest.java b/src/test/java/org/jsoup/nodes/EntitiesTest.java index 886dfca..7243c2f 100644 --- a/src/test/java/org/jsoup/nodes/EntitiesTest.java +++ b/src/test/java/org/jsoup/nodes/EntitiesTest.java @@ -6,6 +6,7 @@ import org.junit.jupiter.api.Test; import static org.jsoup.nodes.Document.OutputSettings; import static org.jsoup.nodes.Entities.EscapeMode.*; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; public class EntitiesTest { @@ -163,4 +164,15 @@ public class EntitiesTest { Document xml = Jsoup.parse(input, "", Parser.xmlParser()); assertEquals(input, xml.html()); } + + @Test public void escapeByClonedOutputSettings() { + OutputSettings outputSettings = new OutputSettings(); + String text = "Hello &<> Å å π 新 there ¾ © »"; + OutputSettings clone1 = outputSettings.clone(); + OutputSettings clone2 = outputSettings.clone(); + + String escaped1 = assertDoesNotThrow(() -> Entities.escape(text, clone1)); + String escaped2 = assertDoesNotThrow(() -> Entities.escape(text, clone2)); + assertEquals(escaped1, escaped2); + } }
https://github.com/jhy/jsoup.gitdiff --git a/src/main/java/org/jsoup/nodes/Document.java b/src/main/java/org/jsoup/nodes/Document.java
gitbug-java_data_jhy-jsoup.json_23
diff --git a/src/main/java/org/jsoup/nodes/Attributes.java b/src/main/java/org/jsoup/nodes/Attributes.java index 76b6590..f246952 100644 --- a/src/main/java/org/jsoup/nodes/Attributes.java +++ b/src/main/java/org/jsoup/nodes/Attributes.java @@ -12,6 +12,7 @@ import java.util.AbstractSet; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.ConcurrentModificationException; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -320,10 +321,12 @@ public class Attributes implements Iterable<Attribute>, Cloneable { public Iterator<Attribute> iterator() { return new Iterator<Attribute>() { + int expectedSize = size; int i = 0; @Override public boolean hasNext() { + checkModified(); while (i < size) { if (isInternalKey(keys[i])) // skip over internal keys i++; @@ -336,14 +339,20 @@ public class Attributes implements Iterable<Attribute>, Cloneable { @Override public Attribute next() { + checkModified(); final Attribute attr = new Attribute(keys[i], (String) vals[i], Attributes.this); i++; return attr; } + private void checkModified() { + if (size != expectedSize) throw new ConcurrentModificationException("Use Iterator#remove() instead to remove attributes while iterating."); + } + @Override public void remove() { Attributes.this.remove(--i); // next() advanced, so rewind + expectedSize--; } }; } diff --git a/src/test/java/org/jsoup/nodes/AttributesTest.java b/src/test/java/org/jsoup/nodes/AttributesTest.java index 58024c6..bb415c0 100644 --- a/src/test/java/org/jsoup/nodes/AttributesTest.java +++ b/src/test/java/org/jsoup/nodes/AttributesTest.java @@ -3,6 +3,7 @@ package org.jsoup.nodes; import org.jsoup.Jsoup; import org.junit.jupiter.api.Test; +import java.util.ConcurrentModificationException; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -175,6 +176,49 @@ public class AttributesTest { } @Test + public void testIteratorRemove() { + String html = "<div 1=1 2=2 3=3 4=4>"; + Document doc = Jsoup.parse(html); + Element el = doc.expectFirst("div"); + Attributes attrs = el.attributes(); + + Iterator<Attribute> iter = attrs.iterator(); + int seen = 0; + while (iter.hasNext()) { + seen++; + Attribute attr = iter.next(); + iter.remove(); + } + assertEquals(4, seen); + assertEquals(0, attrs.size()); + assertEquals(0, el.attributesSize()); + } + + @Test + public void testIteratorRemoveConcurrentException() { + String html = "<div 1=1 2=2 3=3 4=4>"; + Document doc = Jsoup.parse(html); + Element el = doc.expectFirst("div"); + Attributes attrs = el.attributes(); + + Iterator<Attribute> iter = attrs.iterator(); + int seen = 0; + boolean threw = false; + try { + while (iter.hasNext()) { + seen++; + Attribute next = iter.next(); + el.removeAttr(next.getKey()); + } + } catch (ConcurrentModificationException e) { + threw = true; + } + + assertEquals(1, seen); + assertTrue(threw); + } + + @Test public void removeCaseSensitive() { Attributes a = new Attributes(); a.put("Tot", "a&p");
https://github.com/jhy/jsoup.gitdiff --git a/src/main/java/org/jsoup/nodes/Attributes.java b/src/main/java/org/jsoup/nodes/Attributes.java
gitbug-java_data_jhy-jsoup.json_24
diff --git a/src/main/java/org/jsoup/safety/Safelist.java b/src/main/java/org/jsoup/safety/Safelist.java index 710c070..75e80b8 100644 --- a/src/main/java/org/jsoup/safety/Safelist.java +++ b/src/main/java/org/jsoup/safety/Safelist.java @@ -248,6 +248,8 @@ public class Safelist { for (String tagName : tags) { Validate.notEmpty(tagName); + Validate.isFalse(tagName.equalsIgnoreCase("noscript"), + "noscript is unsupported in Safelists, due to incompatibilities between parsers with and without script-mode enabled"); tagNames.add(TagName.valueOf(tagName)); } return this; diff --git a/src/test/java/org/jsoup/safety/SafelistTest.java b/src/test/java/org/jsoup/safety/SafelistTest.java index 8b1c1ff..796ddc7 100644 --- a/src/test/java/org/jsoup/safety/SafelistTest.java +++ b/src/test/java/org/jsoup/safety/SafelistTest.java @@ -1,13 +1,13 @@ package org.jsoup.safety; +import org.jsoup.helper.ValidationException; import org.jsoup.nodes.Attribute; import org.jsoup.nodes.Attributes; import org.jsoup.nodes.Element; import org.jsoup.parser.Tag; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.*; public class SafelistTest { private static final String TEST_TAG = "testTag"; @@ -61,5 +61,19 @@ public class SafelistTest { assertFalse(safelist2.isSafeAttribute(TEST_TAG, invalidElement, invalidAttribute)); } + @Test + void noscriptIsBlocked() { + boolean threw = false; + Safelist safelist = null; + try { + safelist = Safelist.none().addTags("NOSCRIPT"); + } catch (ValidationException validationException) { + threw = true; + assertTrue(validationException.getMessage().contains("unsupported")); + } + assertTrue(threw); + assertNull(safelist); + } + }
https://github.com/jhy/jsoup.gitdiff --git a/src/main/java/org/jsoup/safety/Safelist.java b/src/main/java/org/jsoup/safety/Safelist.java
gitbug-java_data_jhy-jsoup.json_25
diff --git a/src/main/java/org/jsoup/Connection.java b/src/main/java/org/jsoup/Connection.java index 4e279a9..f422deb 100644 --- a/src/main/java/org/jsoup/Connection.java +++ b/src/main/java/org/jsoup/Connection.java @@ -412,11 +412,11 @@ public interface Connection { /** * Get the value of a header. If there is more than one header value with the same name, the headers are returned - * comma seperated, per <a href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2">rfc2616-sec4</a>. + * comma separated, per <a href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2">rfc2616-sec4</a>. * <p> - * Header names are case insensitive. + * Header names are case-insensitive. * </p> - * @param name name of header (case insensitive) + * @param name name of header (case-insensitive) * @return value of header, or null if not set. * @see #hasHeader(String) * @see #cookie(String) @@ -425,14 +425,16 @@ public interface Connection { /** * Get the values of a header. - * @param name header name, case insensitive. + * @param name header name, case-insensitive. * @return a list of values for this header, or an empty list if not set. */ List<String> headers(String name); /** - * Set a header. This method will overwrite any existing header with the same case insensitive name. (If there + * Set a header. This method will overwrite any existing header with the same case-insensitive name. If there * is more than one value for this header, this method will update the first matching header. + * <p>For compatibility, if the content of the header includes text that cannot be represented by ISO-8859-1, + * then it should be encoded first per <a href="https://www.ietf.org/rfc/rfc2047.txt">RFC 2047</a>.</p> * @param name Name of header * @param value Value of header * @return this, for chaining @@ -442,6 +444,8 @@ public interface Connection { /** * Add a header. The header will be added regardless of whether a header with the same name already exists. + * <p>For compatibility, if the content of the header includes text that cannot be represented by ISO-8859-1, + * then it should be encoded first per <a href="https://www.ietf.org/rfc/rfc2047.txt">RFC 2047</a>.</p> * @param name Name of new header * @param value Value of new header * @return this, for chaining @@ -450,22 +454,22 @@ public interface Connection { /** * Check if a header is present - * @param name name of header (case insensitive) + * @param name name of header (case-insensitive) * @return if the header is present in this request/response */ boolean hasHeader(String name); /** * Check if a header is present, with the given value - * @param name header name (case insensitive) - * @param value value (case insensitive) + * @param name header name (case-insensitive) + * @param value value (case-insensitive) * @return if the header and value pair are set in this req/res */ boolean hasHeaderWithValue(String name, String value); /** * Remove headers by name. If there is more than one header with this name, they will all be removed. - * @param name name of header to remove (case insensitive) + * @param name name of header to remove (case-insensitive) * @return this, for chaining */ T removeHeader(String name); diff --git a/src/main/java/org/jsoup/helper/HttpConnection.java b/src/main/java/org/jsoup/helper/HttpConnection.java index d87c9f4..af7a18a 100644 --- a/src/main/java/org/jsoup/helper/HttpConnection.java +++ b/src/main/java/org/jsoup/helper/HttpConnection.java @@ -448,7 +448,7 @@ public class HttpConnection implements Connection { } @Override - public T addHeader(String name, String value) { + public T addHeader(String name, @Nullable String value) { Validate.notEmptyParam(name, "name"); //noinspection ConstantConditions value = value == null ? "" : value; @@ -458,7 +458,7 @@ public class HttpConnection implements Connection { values = new ArrayList<>(); headers.put(name, values); } - values.add(fixHeaderEncoding(value)); + values.add(value); return (T) this; } @@ -469,55 +469,6 @@ public class HttpConnection implements Connection { return getHeadersCaseInsensitive(name); } - private static String fixHeaderEncoding(String val) { - byte[] bytes = val.getBytes(ISO_8859_1); - if (!looksLikeUtf8(bytes)) - return val; - return new String(bytes, UTF_8); - } - - private static boolean looksLikeUtf8(byte[] input) { - int i = 0; - // BOM: - if (input.length >= 3 - && (input[0] & 0xFF) == 0xEF - && (input[1] & 0xFF) == 0xBB - && (input[2] & 0xFF) == 0xBF) { - i = 3; - } - - int end; - for (int j = input.length; i < j; ++i) { - int o = input[i]; - if ((o & 0x80) == 0) { - continue; // ASCII - } - - // UTF-8 leading: - if ((o & 0xE0) == 0xC0) { - end = i + 1; - } else if ((o & 0xF0) == 0xE0) { - end = i + 2; - } else if ((o & 0xF8) == 0xF0) { - end = i + 3; - } else { - return false; - } - - if (end >= input.length) - return false; - - while (i < end) { - i++; - o = input[i]; - if ((o & 0xC0) != 0x80) { - return false; - } - } - } - return true; - } - @Override public T header(String name, String value) { Validate.notEmptyParam(name, "name"); @@ -1162,9 +1113,67 @@ public class HttpConnection implements Connection { } } for (String value : values) { - addHeader(name, value); + addHeader(name, fixHeaderEncoding(value)); + } + } + } + + /** + Servers may encode response headers in UTF-8 instead of RFC defined 8859. This method attempts to detect that + and re-decode the string as UTF-8. + * @param val a header value string that may have been incorrectly decoded as 8859. + * @return a potentially re-decoded string. + */ + @Nullable + private static String fixHeaderEncoding(@Nullable String val) { + if (val == null) return val; + byte[] bytes = val.getBytes(ISO_8859_1); + if (looksLikeUtf8(bytes)) + return new String(bytes, UTF_8); + else + return val; + } + + private static boolean looksLikeUtf8(byte[] input) { + int i = 0; + // BOM: + if (input.length >= 3 + && (input[0] & 0xFF) == 0xEF + && (input[1] & 0xFF) == 0xBB + && (input[2] & 0xFF) == 0xBF) { + i = 3; + } + + int end; + for (int j = input.length; i < j; ++i) { + int o = input[i]; + if ((o & 0x80) == 0) { + continue; // ASCII + } + + // UTF-8 leading: + if ((o & 0xE0) == 0xC0) { + end = i + 1; + } else if ((o & 0xF0) == 0xE0) { + end = i + 2; + } else if ((o & 0xF8) == 0xF0) { + end = i + 3; + } else { + return false; + } + + if (end >= input.length) + return false; + + while (i < end) { + i++; + o = input[i]; + if ((o & 0xC0) != 0x80) { + return false; + } } } + return true; } private @Nullable static String setOutputContentType(final Connection.Request req) { diff --git a/src/test/java/org/jsoup/helper/HttpConnectionTest.java b/src/test/java/org/jsoup/helper/HttpConnectionTest.java index d776588..9444c2d 100644 --- a/src/test/java/org/jsoup/helper/HttpConnectionTest.java +++ b/src/test/java/org/jsoup/helper/HttpConnectionTest.java @@ -358,4 +358,13 @@ public class HttpConnectionTest { } assertTrue(threw); } + + @Test void setHeaderWithUnicodeValue() { + Connection connect = Jsoup.connect("https://example.com"); + String value = "/foo/我的"; + connect.header("Key", value); + + String actual = connect.request().header("Key"); + assertEquals(value, actual); + } }
https://github.com/jhy/jsoup.gitdiff --git a/src/main/java/org/jsoup/Connection.java b/src/main/java/org/jsoup/Connection.java
gitbug-java_data_jhy-jsoup.json_26
diff --git a/src/main/java/org/jsoup/helper/UrlBuilder.java b/src/main/java/org/jsoup/helper/UrlBuilder.java index 4deda36..3ef9c56 100644 --- a/src/main/java/org/jsoup/helper/UrlBuilder.java +++ b/src/main/java/org/jsoup/helper/UrlBuilder.java @@ -90,6 +90,7 @@ final class UrlBuilder { } else if (c > 127) { // out of ascii range sb.append(URLEncoder.encode(new String(Character.toChars(c)), UTF_8.name())); // ^^ is a bit heavy-handed - if perf critical, we could optimize + if (Character.charCount(c) == 2) i++; // advance past supplemental } else { sb.append((char) c); } diff --git a/src/test/java/org/jsoup/helper/HttpConnectionTest.java b/src/test/java/org/jsoup/helper/HttpConnectionTest.java index 9444c2d..8df0f80 100644 --- a/src/test/java/org/jsoup/helper/HttpConnectionTest.java +++ b/src/test/java/org/jsoup/helper/HttpConnectionTest.java @@ -260,6 +260,12 @@ public class HttpConnectionTest { assertEquals("https://test.com/foo%20bar/%5BOne%5D?q=white+space#frag", url2.toExternalForm()); } + @Test public void encodeUrlSupplementary() throws MalformedURLException { + URL url1 = new URL("https://example.com/tools/test💩.html"); // = "/tools/test\uD83D\uDCA9.html" + URL url2 = new UrlBuilder(url1).build(); + assertEquals("https://example.com/tools/test%F0%9F%92%A9.html", url2.toExternalForm()); + } + @Test void encodedUrlDoesntDoubleEncode() throws MalformedURLException { URL url1 = new URL("https://test.com/foo%20bar/%5BOne%5D?q=white+space#frag%20ment"); URL url2 = new UrlBuilder(url1).build();
https://github.com/jhy/jsoup.gitdiff --git a/src/main/java/org/jsoup/helper/UrlBuilder.java b/src/main/java/org/jsoup/helper/UrlBuilder.java
gitbug-java_data_jhy-jsoup.json_27
diff --git a/src/main/java/org/jsoup/nodes/DataNode.java b/src/main/java/org/jsoup/nodes/DataNode.java index 65ae7a3..4a0cf43 100644 --- a/src/main/java/org/jsoup/nodes/DataNode.java +++ b/src/main/java/org/jsoup/nodes/DataNode.java @@ -1,6 +1,7 @@ package org.jsoup.nodes; import java.io.IOException; +import org.jsoup.nodes.Entities.EscapeMode; /** A data node, for contents of style, script tags etc, where contents should not show in text(). @@ -40,7 +41,16 @@ public class DataNode extends LeafNode { @Override void outerHtmlHead(Appendable accum, int depth, Document.OutputSettings out) throws IOException { - accum.append(getWholeData()); // data is not escaped in return from data nodes, so " in script, style is plain + if (out.syntax() == Document.OutputSettings.Syntax.xml) { + // In XML mode, output data nodes as CDATA, so can parse as XML + accum + .append("<![CDATA[") + .append(getWholeData()) + .append("]]>"); + } else { + // In HTML, data is not escaped in return from data nodes, so " in script, style is plain + accum.append(getWholeData()); + } } @Override diff --git a/src/test/java/org/jsoup/helper/W3CDomTest.java b/src/test/java/org/jsoup/helper/W3CDomTest.java index c1daeb5..d79a2b6 100644 --- a/src/test/java/org/jsoup/helper/W3CDomTest.java +++ b/src/test/java/org/jsoup/helper/W3CDomTest.java @@ -345,5 +345,18 @@ public class W3CDomTest { org.jsoup.nodes.TextNode jText = (TextNode) jDiv.childNode(0).childNode(0); assertEquals(jText, textNode.getUserData(W3CDom.SourceProperty)); } + + @Test public void canXmlParseCdataNodes() throws XPathExpressionException { + String html = "<p><script>1 && 2</script><style>3 && 4</style> 5 &amp;&amp; 6</p>"; + org.jsoup.nodes.Document jdoc = Jsoup.parse(html); + jdoc.outputSettings().syntax(org.jsoup.nodes.Document.OutputSettings.Syntax.xml); + String xml = jdoc.body().html(); + assertTrue(xml.contains("<script><![CDATA[")); // as asserted in ElementTest + Document doc = parseXml(xml, false); + NodeList list = xpath(doc, "//script"); + assertEquals(1, list.getLength()); + Node script = list.item(0); // will be the cdata node + assertEquals("1 && 2", script.getTextContent()); + } } diff --git a/src/test/java/org/jsoup/nodes/ElementTest.java b/src/test/java/org/jsoup/nodes/ElementTest.java index bba0940..549a224 100644 --- a/src/test/java/org/jsoup/nodes/ElementTest.java +++ b/src/test/java/org/jsoup/nodes/ElementTest.java @@ -2733,6 +2733,28 @@ public class ElementTest { assertEquals("Hello", parse.data()); } + @Test void datanodesOutputCdataInXhtml() { + String html = "<p><script>1 && 2</script><style>3 && 4</style> 5 &amp;&amp; 6</p>"; + Document doc = Jsoup.parse(html); // parsed as HTML + String out = TextUtil.normalizeSpaces(doc.body().html()); + assertEquals(html, out); + Element scriptEl = doc.expectFirst("script"); + DataNode scriptDataNode = (DataNode) scriptEl.childNode(0); + assertEquals("1 && 2", scriptDataNode.getWholeData()); + + doc.outputSettings().syntax(Document.OutputSettings.Syntax.xml); + String xml = doc.body().html(); + assertEquals( + "<p><script><![CDATA[1 && 2]]></script><style><![CDATA[3 && 4]]></style> 5 &amp;&amp; 6</p>", + TextUtil.normalizeSpaces(xml)); + + Document xmlDoc = Jsoup.parse(xml, Parser.xmlParser()); + assertEquals(xml, xmlDoc.html()); + Element scriptXmlEl = xmlDoc.expectFirst("script"); + CDataNode scriptCdata = (CDataNode) scriptXmlEl.childNode(0); + assertEquals(scriptCdata.text(), scriptDataNode.getWholeData()); + } + @Test void outerHtmlAppendable() { // tests not string builder flow Document doc = Jsoup.parse("<div>One</div>");
https://github.com/jhy/jsoup.gitdiff --git a/src/main/java/org/jsoup/nodes/DataNode.java b/src/main/java/org/jsoup/nodes/DataNode.java
gitbug-java_data_jhy-jsoup.json_28
diff --git a/src/main/java/org/jsoup/select/StructuralEvaluator.java b/src/main/java/org/jsoup/select/StructuralEvaluator.java index 96ff252..560ffbc 100644 --- a/src/main/java/org/jsoup/select/StructuralEvaluator.java +++ b/src/main/java/org/jsoup/select/StructuralEvaluator.java @@ -189,7 +189,9 @@ abstract class StructuralEvaluator extends Evaluator { @Override public boolean matches(Element root, Element element) { - // evaluate from last to first + if (element == root) + return false; // cannot match as the second eval (first parent test) would be above the root + for (int i = evaluators.size() -1; i >= 0; --i) { if (element == null) return false; diff --git a/src/test/java/org/jsoup/select/SelectorTest.java b/src/test/java/org/jsoup/select/SelectorTest.java index 3196dc2..e941f90 100644 --- a/src/test/java/org/jsoup/select/SelectorTest.java +++ b/src/test/java/org/jsoup/select/SelectorTest.java @@ -1181,4 +1181,29 @@ public class SelectorTest { assertEquals("4", notEmpty.get(0).id()); assertEquals("5", notEmpty.get(1).id()); } + + @Test public void parentFromSpecifiedDescender() { + // https://github.com/jhy/jsoup/issues/2018 + String html = "<ul id=outer><li>Foo</li><li>Bar <ul id=inner><li>Baz</li><li>Qux</li></ul> </li></ul>"; + Document doc = Jsoup.parse(html); + + Element ul = doc.expectFirst("#outer"); + assertEquals(2, ul.childrenSize()); + + Element li1 = ul.expectFirst("> li:nth-child(1)"); + assertEquals("Foo", li1.ownText()); + assertTrue(li1.select("ul").isEmpty()); + + Element li2 = ul.expectFirst("> li:nth-child(2)"); + assertEquals("Bar", li2.ownText()); + + // And now for the bug - li2 select was not restricted to the li2 context + Elements innerLis = li2.select("ul > li"); + assertEquals(2, innerLis.size()); + assertEquals("Baz", innerLis.first().ownText()); + + // Confirm that parent selector (" ") works same as immediate parent (">"); + Elements innerLisFromParent = li2.select("ul li"); + assertEquals(innerLis, innerLisFromParent); + } }
https://github.com/jhy/jsoup.gitdiff --git a/src/main/java/org/jsoup/select/StructuralEvaluator.java b/src/main/java/org/jsoup/select/StructuralEvaluator.java
gitbug-java_data_jhy-jsoup.json_29
diff --git a/src/main/java/org/jsoup/select/QueryParser.java b/src/main/java/org/jsoup/select/QueryParser.java index 09f53bd..30872eb 100644 --- a/src/main/java/org/jsoup/select/QueryParser.java +++ b/src/main/java/org/jsoup/select/QueryParser.java @@ -145,18 +145,21 @@ public class QueryParser { private String consumeSubQuery() { StringBuilder sq = StringUtil.borrowBuilder(); + boolean seenNonCombinator = false; // eat until we hit a combinator after eating something else while (!tq.isEmpty()) { if (tq.matches("(")) sq.append("(").append(tq.chompBalanced('(', ')')).append(")"); else if (tq.matches("[")) sq.append("[").append(tq.chompBalanced('[', ']')).append("]"); else if (tq.matchesAny(Combinators)) - if (sq.length() > 0) + if (seenNonCombinator) break; else - tq.consume(); - else + sq.append(tq.consume()); + else { + seenNonCombinator = true; sq.append(tq.consume()); + } } return StringUtil.releaseBuilder(sq); } diff --git a/src/test/java/org/jsoup/select/QueryParserTest.java b/src/test/java/org/jsoup/select/QueryParserTest.java index ae2f344..51b7c92 100644 --- a/src/test/java/org/jsoup/select/QueryParserTest.java +++ b/src/test/java/org/jsoup/select/QueryParserTest.java @@ -18,10 +18,10 @@ public class QueryParserTest { "<a><li><strong>l2</strong></li></a>" + "<p><strong>yes</strong></p>" + "</body></html>"); - assertEquals("l1 l2 yes", doc.body().select(">p>strong,>*>li>strong").text()); + assertEquals("l1 yes", doc.body().select(">p>strong,>li>strong").text()); // selecting immediate from body + assertEquals("l2 yes", doc.select("body>p>strong,body>*>li>strong").text()); + assertEquals("l2 yes", doc.select("body>*>li>strong,body>p>strong").text()); assertEquals("l2 yes", doc.select("body>p>strong,body>*>li>strong").text()); - assertEquals("yes", doc.select(">body>*>li>strong,>body>p>strong").text()); - assertEquals("l2", doc.select(">body>p>strong,>body>*>li>strong").text()); } @Test public void testImmediateParentRun() { diff --git a/src/test/java/org/jsoup/select/SelectorTest.java b/src/test/java/org/jsoup/select/SelectorTest.java index e941f90..686214a 100644 --- a/src/test/java/org/jsoup/select/SelectorTest.java +++ b/src/test/java/org/jsoup/select/SelectorTest.java @@ -1206,4 +1206,17 @@ public class SelectorTest { Elements innerLisFromParent = li2.select("ul li"); assertEquals(innerLis, innerLisFromParent); } + + @Test public void rootImmediateParentSubquery() { + // a combinator at the start of the query is applied to the Root selector. i.e. "> p" matches a P immediately parented + // by the Root (which is <html> for a top level query, or the context element in :has) + // in the sub query, the combinator was dropped incorrectly + String html = "<p id=0><span>A</p> <p id=1><b><i><span>B</p> <p id=2><i>C</p>\n"; + Document doc = Jsoup.parse(html); + + Elements els = doc.select("p:has(> span, > i)"); // should match a p with an immediate span or i + assertEquals(2, els.size()); + assertEquals("0", els.get(0).id()); + assertEquals("2", els.get(1).id()); + } }
https://github.com/jhy/jsoup.gitdiff --git a/src/main/java/org/jsoup/select/QueryParser.java b/src/main/java/org/jsoup/select/QueryParser.java
gitbug-java_data_crowdin-crowdin-api-client-java.json_1
diff --git a/src/main/java/com/crowdin/client/core/http/impl/json/JacksonJsonTransformer.java b/src/main/java/com/crowdin/client/core/http/impl/json/JacksonJsonTransformer.java index 1c925dd..648afaa 100644 --- a/src/main/java/com/crowdin/client/core/http/impl/json/JacksonJsonTransformer.java +++ b/src/main/java/com/crowdin/client/core/http/impl/json/JacksonJsonTransformer.java @@ -44,7 +44,7 @@ public class JacksonJsonTransformer implements JsonTransformer { .addDeserializer(LanguageTranslations.class, new LanguageTranslationsDeserializer(cleanObjectMapper)); this.objectMapper = cleanObjectMapper.copy() .setSerializationInclusion(JsonInclude.Include.NON_NULL) - .setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss+hh:mm")) + .setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX")) .registerModule(module) .setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE) .setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); diff --git a/src/test/java/com/crowdin/client/bundles/BundlesApiTest.java b/src/test/java/com/crowdin/client/bundles/BundlesApiTest.java index f6db9b6..21ff98f 100644 --- a/src/test/java/com/crowdin/client/bundles/BundlesApiTest.java +++ b/src/test/java/com/crowdin/client/bundles/BundlesApiTest.java @@ -19,6 +19,9 @@ import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.TimeZone; +import java.util.Date; +import java.util.Calendar; import static org.junit.jupiter.api.Assertions.*; @@ -35,6 +38,7 @@ public class BundlesApiTest extends TestClient { private final String pattern = "strings-%two_letter_code%.resx"; private final String exportId = "50fb3506-4127-4ba8-8296-f97dc7e3e0c3"; private final String status = "finished"; + private final TimeZone tz = TimeZone.getTimeZone("GMT"); @Override public List<RequestMock> getMocks() { @@ -117,7 +121,9 @@ public class BundlesApiTest extends TestClient { @Test public void downloadBundleTest() { + TimeZone.setDefault(tz); ResponseObject<DownloadLink> response = this.getBundlesApi().downloadBundle(projectId, bundleId, exportId); + assertEquals(new Date(119, Calendar.SEPTEMBER, 20,10,31,21), response.getData().getExpireIn()); assertEquals("test.com", response.getData().getUrl()); } diff --git a/src/test/java/com/crowdin/client/glossaries/GlossariesApiTest.java b/src/test/java/com/crowdin/client/glossaries/GlossariesApiTest.java index 68cb9da..320656c 100644 --- a/src/test/java/com/crowdin/client/glossaries/GlossariesApiTest.java +++ b/src/test/java/com/crowdin/client/glossaries/GlossariesApiTest.java @@ -14,6 +14,9 @@ import org.junit.jupiter.api.Test; import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; +import java.util.TimeZone; +import java.util.Date; +import java.util.Calendar; import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -33,6 +36,7 @@ public class GlossariesApiTest extends TestClient { private final String importId = "c050fba2-200e-4ce1-8de4-f7ba8eb58732"; private final String link = "test.com"; private final String languageId = "ro"; + private final TimeZone tz = TimeZone.getTimeZone("GMT"); @Override public List<RequestMock> getMocks() { @@ -85,9 +89,11 @@ public class GlossariesApiTest extends TestClient { @Test public void getConceptTest() { + TimeZone.setDefault(tz); ResponseObject<Concept> conceptResponseObject = this.getGlossariesApi().getConcept(glossaryId, conceptId); assertEquals(conceptResponseObject.getData().getId(), glossaryId); assertEquals(conceptResponseObject.getData().getSubject(), subject); + assertEquals(new Date(119,Calendar.SEPTEMBER,23,7,19,47), conceptResponseObject.getData().getCreatedAt()); } @Test @@ -199,9 +205,11 @@ public class GlossariesApiTest extends TestClient { @Test public void listTermsTest() { + TimeZone.setDefault(tz); ResponseList<Term> termResponseList = this.getGlossariesApi().listTerms(glossaryId, null, null, null, null, null, null); assertEquals(termResponseList.getData().size(), 1); assertEquals(termResponseList.getData().get(0).getData().getId(), termId); + assertEquals(new Date(119,Calendar.SEPTEMBER,23,7,19,47), termResponseList.getData().get(0).getData().getCreatedAt()); } @Test diff --git a/src/test/java/com/crowdin/client/reports/ReportsApiTest.java b/src/test/java/com/crowdin/client/reports/ReportsApiTest.java index 4f95f1c..8e87ea4 100644 --- a/src/test/java/com/crowdin/client/reports/ReportsApiTest.java +++ b/src/test/java/com/crowdin/client/reports/ReportsApiTest.java @@ -4,6 +4,7 @@ import com.crowdin.client.core.model.*; import com.crowdin.client.framework.RequestMock; import com.crowdin.client.framework.TestClient; import com.crowdin.client.reports.model.*; +import com.crowdin.client.reports.model.Currency; import org.apache.http.client.methods.HttpDelete; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPatch; @@ -13,6 +14,9 @@ import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.TimeZone; +import java.util.Date; +import java.util.Calendar; import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -25,6 +29,7 @@ public class ReportsApiTest extends TestClient { private final String name = "my report template"; private final String id = "50fb3506-4127-4ba8-8296-f97dc7e3e0c3"; private final String link = "test.com"; + private final TimeZone tz = TimeZone.getTimeZone("GMT"); @Override public List<RequestMock> getMocks() { @@ -40,6 +45,7 @@ public class ReportsApiTest extends TestClient { @Test public void generateReportTest() { + TimeZone.setDefault(tz); CostEstimateGenerateReportRequest request = new CostEstimateGenerateReportRequest(); request.setName("costs-estimation"); CostEstimateGenerateReportRequest.Schema schema = new CostEstimateGenerateReportRequest.Schema(); @@ -62,6 +68,7 @@ public class ReportsApiTest extends TestClient { request.setSchema(schema); ResponseObject<ReportStatus> reportStatusResponseObject = this.getReportsApi().generateReport(projectId, request); assertEquals(reportStatusResponseObject.getData().getIdentifier(), id); + assertEquals(new Date(119,Calendar.SEPTEMBER,23,11,26,54), reportStatusResponseObject.getData().getCreatedAt()); } @Test diff --git a/src/test/java/com/crowdin/client/screenshots/ScreenshotsApiTest.java b/src/test/java/com/crowdin/client/screenshots/ScreenshotsApiTest.java index 7d25e89..808a8c6 100644 --- a/src/test/java/com/crowdin/client/screenshots/ScreenshotsApiTest.java +++ b/src/test/java/com/crowdin/client/screenshots/ScreenshotsApiTest.java @@ -22,6 +22,9 @@ import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.List; +import java.util.TimeZone; +import java.util.Date; +import java.util.Calendar; import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -34,6 +37,7 @@ public class ScreenshotsApiTest extends TestClient { private final Long tagId = 98L; private final Long stringId = 12L; private final String name = "translate_with_siri.jpg"; + private final TimeZone tz = TimeZone.getTimeZone("GMT"); @Override public List<RequestMock> getMocks() { @@ -78,11 +82,14 @@ public class ScreenshotsApiTest extends TestClient { @Test public void updateScreenshotTest() { + TimeZone.setDefault(tz); UpdateScreenshotRequest request = new UpdateScreenshotRequest(); request.setName(name); request.setStorageId(storageId); ResponseObject<Screenshot> screenshotResponseObject = this.getScreenshotsApi().updateScreenshot(projectId, screenshotId, request); assertEquals(screenshotResponseObject.getData().getId(), screenshotId); + assertEquals(new Date(119,Calendar.SEPTEMBER,23,9,35,31), screenshotResponseObject.getData().getTags().get(0).getCreatedAt()); + assertEquals(new Date(119,Calendar.SEPTEMBER,23,9,29,19), screenshotResponseObject.getData().getUpdatedAt()); } @Test diff --git a/src/test/java/com/crowdin/client/sourcefiles/SourceFilesApiTest.java b/src/test/java/com/crowdin/client/sourcefiles/SourceFilesApiTest.java index c5f4a2c..bfb141c 100644 --- a/src/test/java/com/crowdin/client/sourcefiles/SourceFilesApiTest.java +++ b/src/test/java/com/crowdin/client/sourcefiles/SourceFilesApiTest.java @@ -19,6 +19,9 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.TimeZone; +import java.util.Date; +import java.util.Calendar; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -40,6 +43,7 @@ public class SourceFilesApiTest extends TestClient { private final String status = "finished"; private final List<Long> attachLabelIds = Arrays.asList(1L); private final List<Long> detachLabelIds = attachLabelIds; + private final TimeZone tz = TimeZone.getTimeZone("GMT"); @Override public List<RequestMock> getMocks() { @@ -130,9 +134,11 @@ public class SourceFilesApiTest extends TestClient { @Test public void getDirectoryTest() { + TimeZone.setDefault(tz); ResponseObject<Directory> directoryResponseObject = this.getSourceFilesApi().getDirectory(projectId, directoryId); assertEquals(directoryResponseObject.getData().getId(), directoryId); assertEquals(directoryResponseObject.getData().getName(), directoryName); + assertEquals(new Date(119,Calendar.SEPTEMBER,19,14,14,0),directoryResponseObject.getData().getCreatedAt()); } @Test diff --git a/src/test/java/com/crowdin/client/tasks/TasksApiTest.java b/src/test/java/com/crowdin/client/tasks/TasksApiTest.java index d3d2fa8..efbc40b 100644 --- a/src/test/java/com/crowdin/client/tasks/TasksApiTest.java +++ b/src/test/java/com/crowdin/client/tasks/TasksApiTest.java @@ -19,7 +19,10 @@ import org.apache.http.client.methods.HttpPost; import org.junit.jupiter.api.Test; import java.util.Arrays; +import java.util.Date; import java.util.List; +import java.util.TimeZone; +import java.util.Calendar; import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -50,10 +53,12 @@ public class TasksApiTest extends TestClient { @Test public void listTasksTest() { + TimeZone.setDefault(TimeZone.getTimeZone("GMT")); ResponseList<Task> taskResponseList = this.getTasksApi().listTasks(projectId, null, null, null); assertEquals(taskResponseList.getData().size(), 1); assertEquals(taskResponseList.getData().get(0).getData().getId(), taskId); assertEquals(taskResponseList.getData().get(0).getData().getStatus(), status); + assertEquals(new Date(119, Calendar.SEPTEMBER,27,7,0,14), taskResponseList.getData().get(0).getData().getDeadline()); } @Test @@ -89,11 +94,14 @@ public class TasksApiTest extends TestClient { @Test public void getTaskTest() { + TimeZone.setDefault(TimeZone.getTimeZone("GMT")); ResponseObject<Task> taskResponseObject = this.getTasksApi().getTask(projectId, taskId); + Date createdAt = new Date(119,Calendar.SEPTEMBER,23,9,4,29); assertEquals(taskResponseObject.getData().getId(), taskId); assertEquals(taskResponseObject.getData().getStatus(), status); assertNotNull(taskResponseObject.getData().getTranslateProgress()); assertEquals(62, taskResponseObject.getData().getTranslateProgress().getPercent().intValue()); + assertEquals(createdAt, taskResponseObject.getData().getCreatedAt()); } @Test
https://github.com/crowdin/crowdin-api-client-java.gitdiff --git a/src/main/java/com/crowdin/client/core/http/impl/json/JacksonJsonTransformer.java b/src/main/java/com/crowdin/client/core/http/impl/json/JacksonJsonTransformer.java
gitbug-java_data_awslabs-aws-java-nio-spi-for-s3.json_1
diff --git a/src/main/java/software/amazon/nio/spi/s3/S3FileSystem.java b/src/main/java/software/amazon/nio/spi/s3/S3FileSystem.java index 5ba4585..b9e1f38 100644 --- a/src/main/java/software/amazon/nio/spi/s3/S3FileSystem.java +++ b/src/main/java/software/amazon/nio/spi/s3/S3FileSystem.java @@ -12,7 +12,16 @@ import java.io.File; import java.io.IOException; import java.net.URI; import java.nio.channels.Channel; -import java.nio.file.*; +import java.nio.file.ClosedFileSystemException; +import java.nio.file.DirectoryStream; +import java.nio.file.FileStore; +import java.nio.file.FileSystem; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.InvalidPathException; +import java.nio.file.Path; +import java.nio.file.PathMatcher; +import java.nio.file.WatchService; import java.nio.file.attribute.UserPrincipalLookupService; import java.nio.file.spi.FileSystemProvider; import java.util.Collections; @@ -182,7 +191,7 @@ public class S3FileSystem extends FileSystem { */ @Override public Iterable<Path> getRootDirectories() { - return S3Path.getPath(this, "/"); + return Collections.singleton(S3Path.getPath(this, "/")); } /** diff --git a/src/test/java/software/amazon/nio/spi/s3/S3FileSystemTest.java b/src/test/java/software/amazon/nio/spi/s3/S3FileSystemTest.java index 31080f7..2d44d75 100644 --- a/src/test/java/software/amazon/nio/spi/s3/S3FileSystemTest.java +++ b/src/test/java/software/amazon/nio/spi/s3/S3FileSystemTest.java @@ -13,8 +13,12 @@ import java.net.URI; import java.nio.file.FileSystems; import java.nio.file.Path; import java.util.Collections; +import java.util.Iterator; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; public class S3FileSystemTest { S3FileSystemProvider provider; @@ -60,8 +64,12 @@ public class S3FileSystemTest { public void getRootDirectories() { final Iterable<Path> rootDirectories = s3FileSystem.getRootDirectories(); assertNotNull(rootDirectories); - assertEquals(S3Path.PATH_SEPARATOR, rootDirectories.toString()); - assertFalse(s3FileSystem.getRootDirectories().iterator().hasNext()); + + final Iterator<Path> rootDirectoriesIterator = rootDirectories.iterator(); + + assertTrue(rootDirectoriesIterator.hasNext()); + assertEquals(S3Path.PATH_SEPARATOR, rootDirectoriesIterator.next().toString()); + assertFalse(rootDirectoriesIterator.hasNext()); } @Test
https://github.com/awslabs/aws-java-nio-spi-for-s3.gitdiff --git a/src/main/java/software/amazon/nio/spi/s3/S3FileSystem.java b/src/main/java/software/amazon/nio/spi/s3/S3FileSystem.java
gitbug-java_data_awslabs-aws-java-nio-spi-for-s3.json_2
diff --git a/src/main/java/software/amazon/nio/spi/s3/S3Path.java b/src/main/java/software/amazon/nio/spi/s3/S3Path.java index 1da52a2..914689a 100644 --- a/src/main/java/software/amazon/nio/spi/s3/S3Path.java +++ b/src/main/java/software/amazon/nio/spi/s3/S3Path.java @@ -9,7 +9,9 @@ import software.amazon.awssdk.services.s3.model.S3Object; import java.io.File; import java.io.IOError; +import java.io.UnsupportedEncodingException; import java.net.URI; +import java.net.URLEncoder; import java.nio.file.FileSystem; import java.nio.file.InvalidPathException; import java.nio.file.LinkOption; @@ -599,7 +601,24 @@ public class S3Path implements Path { * * <p> This method constructs an absolute and normalized {@link URI} with a {@link * URI#getScheme() scheme} equal to the URI scheme that identifies the - * provider (s3). + * provider (s3). Please note that the returned URI is a well formed URI, + * which means all special characters (e.g. blanks, %, ?, etc.) are encoded. + * This may result in a different string from the real path (object key), + * which instead allows those characters. + * + * For instance, the S3 URI "s3://mybucket/with space and %" is a valid S3 + * object key, which must be encoded when creating a Path and that will be + * encoded when creating a URI. E.g.: + * + * <pre> + * {@code + * S3Path p = (S3Path)Paths.get("s3://mybucket/with+blank+and+%25"); // -> s3://mybucket/with blank and % + * String s = p.toString; // -> /mybucket/with blank and % + * URI u = p.toUri(); --> // -> s3://mybucket/with+blank+and+%25 + * ... + * String s = p.getFileSystem().get("with space").toString(); // -> /with space + * } + * </pre> * * @return the URI representing this path * @throws IOError if an I/O error occurs obtaining the absolute path, or where a @@ -610,12 +629,35 @@ public class S3Path implements Path { * is installed, the {@link #toAbsolutePath toAbsolutePath} method * throws a security exception. */ + @Override public URI toUri() { - return URI.create( - fileSystem.provider().getScheme() + "://" - + bucketName() - + this.toAbsolutePath().toRealPath(NOFOLLOW_LINKS)); + Path path = toAbsolutePath().toRealPath(NOFOLLOW_LINKS); + Iterator<Path> elements = path.iterator(); + + StringBuilder uri = new StringBuilder(fileSystem.provider().getScheme() + "://"); + uri.append(bucketName()); + elements.forEachRemaining( + (e) -> { + String name = e.getFileName().toString(); + try { + if (name.endsWith(PATH_SEPARATOR)) { + name = name.substring(0, name.length()-1); + } + uri.append(PATH_SEPARATOR).append(URLEncoder.encode(name, "UTF-8")); + } catch (UnsupportedEncodingException x) { + // + // NOTE: I do not know how to reproduce this case... + // + throw new IllegalArgumentException("path '" + uri + "' can not be converted to URI: " + x.getMessage(), x); + } + } + ); + if (isDirectory()) { + uri.append(PATH_SEPARATOR); + } + + return URI.create(uri.toString()); } /** diff --git a/src/test/java/software/amazon/nio/spi/s3/S3PathTest.java b/src/test/java/software/amazon/nio/spi/s3/S3PathTest.java index 82edbe0..e50e748 100644 --- a/src/test/java/software/amazon/nio/spi/s3/S3PathTest.java +++ b/src/test/java/software/amazon/nio/spi/s3/S3PathTest.java @@ -25,6 +25,7 @@ public class S3PathTest { S3Path relativeDirectory; S3Path absoluteObject; S3Path relativeObject; + S3Path withSpecialChars; @BeforeEach public void init(){ @@ -33,6 +34,7 @@ public class S3PathTest { relativeDirectory = S3Path.getPath(fileSystem, "..", "dir3/"); absoluteObject = S3Path.getPath(fileSystem, S3Path.PATH_SEPARATOR, "dir1", "dir2", "object"); relativeObject = S3Path.getPath(fileSystem, "dir1", "dir2", "object"); + withSpecialChars = S3Path.getPath(fileSystem, "dir with space/and\tspecial&chars"); } @Test @@ -326,12 +328,14 @@ public class S3PathTest { final URI uri1 = URI.create("s3://mybucket/dir1/dir2/object"); final URI uri2 = URI.create("s3://mybucket/"); final URI uri3 = URI.create("s3://mybucket/dir3/"); + final URI uri4 = URI.create("s3://mybucket/dir+with+space/and%09special%26chars"); assertEquals(uri, absoluteDirectory.toUri()); assertEquals(uri3, relativeDirectory.toUri()); assertEquals(uri1, relativeObject.toUri()); assertEquals(uri1, absoluteObject.toUri()); assertEquals(uri2, root.toUri()); + assertEquals(uri4, withSpecialChars.toUri()); } @Test
https://github.com/awslabs/aws-java-nio-spi-for-s3.gitdiff --git a/src/main/java/software/amazon/nio/spi/s3/S3Path.java b/src/main/java/software/amazon/nio/spi/s3/S3Path.java
gitbug-java_data_salesforce-grammaticus.json_1
diff --git a/src/main/java/com/force/i18n/grammar/impl/GrammaticalTermMapImpl.java b/src/main/java/com/force/i18n/grammar/impl/GrammaticalTermMapImpl.java index c53fa3f..10cb487 100644 --- a/src/main/java/com/force/i18n/grammar/impl/GrammaticalTermMapImpl.java +++ b/src/main/java/com/force/i18n/grammar/impl/GrammaticalTermMapImpl.java @@ -27,10 +27,13 @@ import static com.force.i18n.commons.util.settings.IniFileUtil.intern; * @author ytanida */ public class GrammaticalTermMapImpl<T extends GrammaticalTerm> implements GrammaticalTermMap<T>, Serializable { - protected Map<String, T> map; + private static final long serialVersionUID = 2099717329853215271L; + + protected transient Map<String, T> map; private boolean isSkinny = false; + public GrammaticalTermMapImpl() { - map = new HashMap<String, T>(); + map = new HashMap<>(); } public GrammaticalTermMapImpl(Map<String, T> map, boolean isSkinny) { @@ -49,6 +52,7 @@ public class GrammaticalTermMapImpl<T extends GrammaticalTerm> implements Gramma if(!(obj instanceof GrammaticalTermMapImpl)) return false; + @SuppressWarnings("unchecked") GrammaticalTermMapImpl<T> other = (GrammaticalTermMapImpl<T>)obj; return isSkinny == other.isSkinny && map.equals(other.map); } @@ -65,12 +69,12 @@ public class GrammaticalTermMapImpl<T extends GrammaticalTerm> implements Gramma @Override public GrammaticalTermMap<T> makeSkinny() { - return new GrammaticalTermMapImpl<T>(map, true); + return new GrammaticalTermMapImpl<>(map, true); } @Override public void writeJson(Appendable out, RenamingProvider renamingProvider, LanguageDictionary dictionary, Collection<String> termsToInclude) throws IOException { - Set<String> wrote = new HashSet<String>(); + Set<String> wrote = new HashSet<>(); out.append('{'); if (termsToInclude != null) { boolean first = true; @@ -166,7 +170,9 @@ public class GrammaticalTermMapImpl<T extends GrammaticalTerm> implements Gramma * @param in * @throws IOException */ + @SuppressWarnings("unchecked") private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { + in.defaultReadObject(); this.map = ((TermMapSerializer<T>)in.readObject()).getMap(); } @@ -176,7 +182,8 @@ public class GrammaticalTermMapImpl<T extends GrammaticalTerm> implements Gramma * @throws IOException */ private void writeObject(ObjectOutputStream out) throws IOException { - out.writeObject(new TermMapSerializer<T>(map)); + out.defaultWriteObject(); + out.writeObject(new TermMapSerializer<>(map)); } static final class TermMapSerializer<T extends GrammaticalTerm> extends MapSerializer<String, T> { diff --git a/src/test/java/com/force/i18n/grammar/impl/GrammaticalTermMapImplTest.java b/src/test/java/com/force/i18n/grammar/impl/GrammaticalTermMapImplTest.java index cfb9d7a..1b59bb0 100644 --- a/src/test/java/com/force/i18n/grammar/impl/GrammaticalTermMapImplTest.java +++ b/src/test/java/com/force/i18n/grammar/impl/GrammaticalTermMapImplTest.java @@ -7,6 +7,11 @@ package com.force.i18n.grammar.impl; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + import java.util.HashSet; import java.util.Locale; import junit.framework.TestCase; @@ -79,8 +84,63 @@ public class GrammaticalTermMapImplTest extends TestCase { } } + @SuppressWarnings("unchecked") + public void testSerialization() throws Exception { + GrammaticalTermMapImpl<Noun> map = new GrammaticalTermMapImpl<>(); + assertSerializedEquals(map); + Noun n1 = createNoun("n1"); + map.put("one", createNoun("one")); + map.put("two", createNoun("two")); + assertSerializedEquals(map); + assertSerializedEquals((GrammaticalTermMapImpl<Noun>)map.makeSkinny()); + map.put("n1", n1); + map.put("n1_a", n1); + GrammaticalTermMapImpl<Noun> serialized = getSerialized(map); + // same noun should be same in serialized map + assertTrue(serialized.get("n1") == serialized.get("n1_a")); + } /** + * Verify map is same after serialization + * @param orig the original map + * @throws Exception + */ + private void assertSerializedEquals(GrammaticalTermMapImpl<Noun> orig) throws Exception { + GrammaticalTermMapImpl<Noun> serialized = getSerialized(orig); + assertEquals("isEmpty returns differently", orig.isEmpty(), serialized.isEmpty()); + assertEquals("keySet returns different", orig.keySet().size(), serialized.keySet().size()); + + for (String key : orig.keySet()) { + assertTrue("serialized map doesn't have "+key, serialized.containsKey(key)); + assertEquals("serialized map have different noun", orig.get(key), serialized.get(key)); + } + assertEquals("The map returns different isSkinny ", orig.isSkinny(), serialized.isSkinny()); + } + + /** + * Serialize and deserialize a map. + * @param input the map to serialize + * @return the serialized map + * @throws Exception if there's an error + */ + @SuppressWarnings("unchecked") + private GrammaticalTermMapImpl<Noun> getSerialized(GrammaticalTermMapImpl<Noun> input) throws Exception{ + // Serialize + byte[] array = null; + try ( ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(baos)) { + oos.writeObject(input); + array = baos.toByteArray(); + } + assertNotNull(array); + // Deserialize + try ( ByteArrayInputStream bais = new ByteArrayInputStream(array); + ObjectInputStream ois = new ObjectInputStream(bais)){ + return (GrammaticalTermMapImpl<Noun>) ois.readObject(); + } + } + + /** * Create a noun for testing */ public Noun createNoun(String some) {
https://github.com/salesforce/grammaticus.gitdiff --git a/src/main/java/com/force/i18n/grammar/impl/GrammaticalTermMapImpl.java b/src/main/java/com/force/i18n/grammar/impl/GrammaticalTermMapImpl.java
gitbug-java_data_AuthMe-ConfigMe.json_1
diff --git a/src/main/java/ch/jalu/configme/configurationdata/PropertyListBuilder.java b/src/main/java/ch/jalu/configme/configurationdata/PropertyListBuilder.java index ea010a0..44ad63b 100644 --- a/src/main/java/ch/jalu/configme/configurationdata/PropertyListBuilder.java +++ b/src/main/java/ch/jalu/configme/configurationdata/PropertyListBuilder.java @@ -11,7 +11,7 @@ import java.util.Map; /** * Builds a list of known properties in an ordered and grouped manner. - * + * <p> * It guarantees that the added entries: * <ul> * <li>are grouped by path, e.g. all "DataSource.mysql" properties are together, and "DataSource.mysql" properties @@ -24,7 +24,7 @@ import java.util.Map; */ public class PropertyListBuilder { - private @NotNull Map<String, Object> rootEntries = new LinkedHashMap<>(); + private final @NotNull Map<String, Object> rootEntries = new LinkedHashMap<>(); /** * Adds the property to the list builder. @@ -32,17 +32,16 @@ public class PropertyListBuilder { * @param property the property to add */ public void add(@NotNull Property<?> property) { - String[] paths = property.getPath().split("\\."); - Map<String, Object> map = rootEntries; - for (int i = 0; i < paths.length - 1; ++i) { - map = getChildMap(map, paths[i]); - } + String[] pathElements = property.getPath().split("\\.", -1); + Map<String, Object> mapForProperty = getMapBeforeLastElement(pathElements); - final String end = paths[paths.length - 1]; - if (map.containsKey(end)) { + final String lastElement = pathElements[pathElements.length - 1]; + if (mapForProperty.containsKey(lastElement)) { throw new ConfigMeException("Path at '" + property.getPath() + "' already exists"); + } else if (pathElements.length > 1 && lastElement.equals("")) { + throwExceptionForMalformedPath(property.getPath()); } - map.put(end, property); + mapForProperty.put(lastElement, property); } /** @@ -54,9 +53,36 @@ public class PropertyListBuilder { public @NotNull List<Property<?>> create() { List<Property<?>> result = new ArrayList<>(); collectEntries(rootEntries, result); + if (result.size() > 1 && rootEntries.containsKey("")) { + throw new ConfigMeException("A property at the root path (\"\") cannot be defined alongside " + + "other properties as the paths would conflict"); + } return result; } + /** + * Returns the nested map for the given path parts in which a property can be saved (for the last element + * in the path parts). Throws an exception if the path is malformed. + * + * @param pathParts the path elements (i.e. the property path split by ".") + * @return the map to store the property in + */ + protected @NotNull Map<String, Object> getMapBeforeLastElement(String @NotNull [] pathParts) { + Map<String, Object> map = rootEntries; + for (int i = 0; i < pathParts.length - 1; ++i) { + map = getChildMap(map, pathParts[i]); + if (pathParts[i].equals("")) { + throwExceptionForMalformedPath(String.join(".", pathParts)); + } + } + return map; + } + + protected void throwExceptionForMalformedPath(@NotNull String path) { + throw new ConfigMeException("The path at '" + path + "' is malformed: dots may not be at the beginning or end " + + "of a path, and dots may not appear multiple times successively."); + } + protected final @NotNull Map<String, Object> getRootEntries() { return rootEntries; } diff --git a/src/test/java/ch/jalu/configme/configurationdata/PropertyListBuilderTest.java b/src/test/java/ch/jalu/configme/configurationdata/PropertyListBuilderTest.java index 3352f36..c7b2e4a 100644 --- a/src/test/java/ch/jalu/configme/configurationdata/PropertyListBuilderTest.java +++ b/src/test/java/ch/jalu/configme/configurationdata/PropertyListBuilderTest.java @@ -4,10 +4,13 @@ import ch.jalu.configme.exception.ConfigMeException; import ch.jalu.configme.properties.Property; import ch.jalu.configme.properties.StringProperty; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.stream.Stream; import static ch.jalu.configme.TestUtils.transform; import static org.hamcrest.MatcherAssert.assertThat; @@ -102,6 +105,54 @@ class PropertyListBuilderTest { assertThat(properties.create(), hasSize(1)); } + @Test + void shouldSupportRootProperty() { + // given + PropertyListBuilder listBuilder = new PropertyListBuilder(); + Property<?> rootProperty = createPropertyWithPath(""); + listBuilder.add(rootProperty); + + // when + List<Property<?>> properties = listBuilder.create(); + + // then + assertThat(properties, contains(rootProperty)); + } + + @Test + void shouldThrowForRootPathAndOtherProperty() { + // given + PropertyListBuilder properties = new PropertyListBuilder(); + properties.add(createPropertyWithPath("")); + properties.add(createPropertyWithPath("enabled")); + + // when + ConfigMeException ex = assertThrows(ConfigMeException.class, properties::create); + + // then + assertThat(ex.getMessage(), + equalTo("A property at the root path (\"\") cannot be defined alongside other properties as the paths would conflict")); + } + + @ParameterizedTest + @MethodSource("malformedPropertyPaths") + void shouldThrowForMalformedPropertyPath(String path) { + // given + PropertyListBuilder properties = new PropertyListBuilder(); + + // when + ConfigMeException ex = assertThrows(ConfigMeException.class, + () -> properties.add(createPropertyWithPath(path))); + + // then + assertThat(ex.getMessage(), equalTo("The path at '" + path + "' is malformed: dots may not be at " + + "the beginning or end of a path, and dots may not appear multiple times successively.")); + } + + static Stream<String> malformedPropertyPaths() { + return Stream.of(".", "..", ".security", "security.", "alf..beta", "security.hash..version.minor"); + } + private static Property<?> createPropertyWithPath(String path) { return new StringProperty(path, ""); }
https://github.com/AuthMe/ConfigMe.gitdiff --git a/src/main/java/ch/jalu/configme/configurationdata/PropertyListBuilder.java b/src/main/java/ch/jalu/configme/configurationdata/PropertyListBuilder.java
gitbug-java_data_AuthMe-ConfigMe.json_2
diff --git a/src/main/java/ch/jalu/configme/configurationdata/CommentsConfiguration.java b/src/main/java/ch/jalu/configme/configurationdata/CommentsConfiguration.java index 225e0c4..0f050ce 100644 --- a/src/main/java/ch/jalu/configme/configurationdata/CommentsConfiguration.java +++ b/src/main/java/ch/jalu/configme/configurationdata/CommentsConfiguration.java @@ -41,7 +41,11 @@ public class CommentsConfiguration { * @param commentLines the comment lines to set for the path */ public void setComment(@NotNull String path, @NotNull String... commentLines) { - comments.put(path, Collections.unmodifiableList(Arrays.asList(commentLines))); + List<String> replaced = comments.put(path, Collections.unmodifiableList(Arrays.asList(commentLines))); + + if (replaced != null) { + throw new IllegalStateException("Comment lines already exists for the path '" + path + "'"); + } } /** diff --git a/src/test/java/ch/jalu/configme/configurationdata/CommentsConfigurationTest.java b/src/test/java/ch/jalu/configme/configurationdata/CommentsConfigurationTest.java index c3c30b3..7afed0a 100644 --- a/src/test/java/ch/jalu/configme/configurationdata/CommentsConfigurationTest.java +++ b/src/test/java/ch/jalu/configme/configurationdata/CommentsConfigurationTest.java @@ -11,6 +11,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.equalTo; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * Test for {@link CommentsConfiguration}. @@ -18,6 +19,22 @@ import static org.hamcrest.Matchers.equalTo; class CommentsConfigurationTest { @Test + void shouldThrowForExistingPath() { + // given + final String path = "config.me"; + CommentsConfiguration conf = new CommentsConfiguration(); + conf.setComment(path, "Old", "Comments", "1", "2", "3"); + + // when + IllegalStateException ex = assertThrows(IllegalStateException.class, () -> conf.setComment(path, "New Comment")); + + // then + assertThat(ex.getMessage(), equalTo("Comment lines already exists for the path 'config.me'")); + assertThat(conf.getAllComments().keySet(), contains(path)); + assertThat(conf.getAllComments().get(path), contains("New Comment")); + } + + @Test void shouldOverrideExistingComment() { // given CommentsConfiguration conf = new CommentsConfiguration(); @@ -25,9 +42,11 @@ class CommentsConfigurationTest { conf.setComment("other.path", "Some other", "path I am", "adding"); // when - conf.setComment("com.acme", "Acme new comment", "1, 2, 3"); + IllegalStateException ex = assertThrows(IllegalStateException.class, ()-> conf.setComment("com.acme", "Acme new comment", "1, 2, 3")); // then + assertThat(ex.getMessage(), equalTo("Comment lines already exists for the path 'com.acme'")); + Map<String, List<String>> allComments = conf.getAllComments(); assertThat(allComments.keySet(), containsInAnyOrder("com.acme", "other.path")); assertThat(allComments.get("com.acme"), contains("Acme new comment", "1, 2, 3"));
https://github.com/AuthMe/ConfigMe.gitdiff --git a/src/main/java/ch/jalu/configme/configurationdata/CommentsConfiguration.java b/src/main/java/ch/jalu/configme/configurationdata/CommentsConfiguration.java
gitbug-java_data_traccar-traccar.json_1
diff --git a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java index 15588c8..ef09677 100644 --- a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -803,7 +803,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { getLastLocation(position, null); } - if (hasLbs(type)) { + if (hasLbs(type) && buf.readableBytes() > 6) { decodeLbs(position, buf, type, hasStatus(type) && type != MSG_LBS_ALARM); } diff --git a/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java index 9d0716c..23c29b0 100644 --- a/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java @@ -17,6 +17,9 @@ public class Gt06ProtocolDecoderTest extends ProtocolTest { verifyNull(decoder, binary( "78780D01086471700328358100093F040D0A")); + verifyPosition(decoder, binary( + "78781511170103100e1f9904efe30400a97f88003410ffdd000d0a")); + verifyAttribute(decoder, binary( "787819a5012ed0000075df000000000098661502050413000019a12b0d0a"), Position.KEY_ALARM, Position.ALARM_TAMPERING);
https://github.com/traccar/traccar.gitdiff --git a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java
gitbug-java_data_traccar-traccar.json_2
diff --git a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java index ef09677..5b639dd 100644 --- a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -99,7 +99,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { public static final int MSG_LBS_2 = 0xA1; // GK310 public static final int MSG_WIFI_3 = 0xA2; // GK310 public static final int MSG_FENCE_SINGLE = 0xA3; // GK310 - public static final int MSG_FENCE_MULTI = 0xA4; // GK310 + public static final int MSG_FENCE_MULTI = 0xA4; // GK310 & JM-LL301 public static final int MSG_LBS_ALARM = 0xA5; // GK310 & JM-LL301 public static final int MSG_LBS_ADDRESS = 0xA7; // GK310 public static final int MSG_OBD = 0x8C; // FM08ABC @@ -209,6 +209,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { case MSG_GPS_LBS_STATUS_2: case MSG_GPS_LBS_STATUS_3: case MSG_GPS_LBS_STATUS_4: + case MSG_FENCE_MULTI: case MSG_LBS_ALARM: return true; default: @@ -804,7 +805,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { } if (hasLbs(type) && buf.readableBytes() > 6) { - decodeLbs(position, buf, type, hasStatus(type) && type != MSG_LBS_ALARM); + decodeLbs(position, buf, type, hasStatus(type) && type != MSG_LBS_ALARM && type != MSG_LBS_STATUS); } if (hasStatus(type)) { diff --git a/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java index 23c29b0..697908a 100644 --- a/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/Gt06ProtocolDecoderTest.java @@ -17,6 +17,18 @@ public class Gt06ProtocolDecoderTest extends ProtocolTest { verifyNull(decoder, binary( "78780D01086471700328358100093F040D0A")); + verifyAttribute(decoder, binary( + "78781219012ed042cc00954d00040419000056fe290d0a"), + Position.KEY_ALARM, Position.ALARM_LOW_BATTERY); + + verifyAttribute(decoder, binary( + "78782DA4150817073B10CF032EEA9C0B6CE0800015141001CC0100009A00000000000A6F24014605041900FF01908A640D0A"), + Position.KEY_ALARM, Position.ALARM_LOW_BATTERY); + + verifyAttribute(decoder, binary( + "78782627100419092D07C5027AC91C0C4658000005370900000000000000008002001900FF00004DF60D0A"), + Position.KEY_ALARM, Position.ALARM_LOW_BATTERY); + verifyPosition(decoder, binary( "78781511170103100e1f9904efe30400a97f88003410ffdd000d0a"));
https://github.com/traccar/traccar.gitdiff --git a/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Gt06ProtocolDecoder.java
gitbug-java_data_traccar-traccar.json_3
diff --git a/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java b/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java index 142d1b6..6fb626d 100644 --- a/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java @@ -263,7 +263,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { Position position = decodePosition(deviceSession, buf.toString(StandardCharsets.US_ASCII)); if (type.startsWith("AL")) { - if (position != null) { + if (position != null && !position.hasAttribute(Position.KEY_ALARM)) { position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); } sendResponse(channel, id, index, "AL"); @@ -279,6 +279,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { || type.equalsIgnoreCase("HEART") || type.equalsIgnoreCase("BLOOD") || type.equalsIgnoreCase("BPHRT") + || type.equalsIgnoreCase("TEMP") || type.equalsIgnoreCase("btemp2")) { if (buf.isReadable()) { @@ -291,7 +292,9 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { String[] values = buf.toString(StandardCharsets.US_ASCII).split(","); int valueIndex = 0; - if (type.equalsIgnoreCase("btemp2")) { + if (type.equalsIgnoreCase("TEMP")) { + position.set(Position.PREFIX_TEMP + 1, Double.parseDouble(values[valueIndex])); + } else if (type.equalsIgnoreCase("btemp2")) { if (Integer.parseInt(values[valueIndex++]) > 0) { position.set(Position.PREFIX_TEMP + 1, Double.parseDouble(values[valueIndex])); } diff --git a/src/test/java/org/traccar/protocol/WatchProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/WatchProtocolDecoderTest.java index 7eb167a..0ffe819 100644 --- a/src/test/java/org/traccar/protocol/WatchProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/WatchProtocolDecoderTest.java @@ -17,6 +17,14 @@ public class WatchProtocolDecoderTest extends ProtocolTest { var decoder = inject(new WatchProtocolDecoder(null)); + verifyAttribute(decoder, buffer( + "[ZJ*5678901234*0001*0009*TEMP,36.5]"), + Position.PREFIX_TEMP + 1, 36.5); + + verifyAttribute(decoder, buffer( + "[ZJ*689466020014198*0003*0113*AL,221121,085515,V,00.000000,N,000.000000,E,0,0,0,0,0,44,0,0,00100000,1,255,460,0,16399,234887445,0,6,WIFI00,68:77:24:1b:e7:a7,-59,WIFI01,68:77:24:1b:e3:30,-75,WIFI02,68:77:24:1b:e3:27,-75,WIFI03,00:41:d2:c0:f2:f1,-76,WIFI04,00:41:d2:c0:f2:f0,-77,WIFI05,68:77:24:1b:e3:d8,-82]"), + Position.KEY_ALARM, Position.ALARM_REMOVING); + verifyNull(decoder, binary( "5b5a4a2a3738393436383035303034323639322a303033342a303433392a4a58544b2c302c77617463685f375f32303232303532363039333935342c312c362c2321414d520a0c0a3c3f96d98367e9468ea245320c0a3c3f96d98367e9468ea245320c0a3c3f96d98367e9468ea245320c389814ffcd762fe49d50ae7a2e0cb528aefbf76911df05c2fbe17d050c2200cff77ef0df4d9b4ab9a4340c449814dbe7c63fa82bc3750d800cc48abbffddb0df8e8fda95e5980c49982ff6cf65f9377d02a39c3aaa0c389805f2ff42c1b80e0a0eb1dc0c2998e9defe15cfa3bdbe80d3540c7298c2f6d9239e3eae3c4a81660c490034dbfd513fedad0c2fc3900cc40039b7f71bb0657ba75558c40cd7813b97ff7219777ec7f401260c7d040003bff6f75fdb898a6ba1140cecd127f7f83357cb73a68a5f680cb081d4f6e749e6af8ed367bc480cec1815dfffd2dbed358112af320ccc21179fffbd17a3a61c133b380c920047defc72a784770ec0fe400c383c42f6faebe76fa736e9d1be0c4918e7decddc67ec9afd87ff220cc418e6bffe6cf6c9ac1f83c3900ca6cad1ffe3da24e1be3b547d03c00c6b00b8fee77f60a76d3e7d0292e20c2918b7bfff76387b793d3a36300c7d0400b7fff7f63ae513ac6f74de0c980016fbff7d01f9b30fca67c7220caa982ff6dbd7bf3d8dfed143ec0c44982fdfcb7b517e26f6ea52420c0ed19cfedb438f179d3fc50ec40c008ad2ffff635fe28dc1ec1f860c76cb7d05bffda53eaebe4d201ae20ccccaffbbfd3db4abb6ddf39d0e0c6b00acfeff406fe4a12661caf80c76982fbffffeb17b2f65472f300c7d04c24bf6ef1b10e47f73fc10b40c76036cfecd4e7837145a6a8e900ccccaf2beeba36fbaa36feb60640c7d0400dfffff73bfa3b87d0256a1700c7d04e4efd6efc23b651eb73e77780ccc1813ffffb39f6baa6f3195080c00007afffee0b9df6346ca08d00c6bca7d04feff4d64a7b56f9855da0c769819fbfd954ea5bd7d040ba6420c4c4c09bfffd5f6c57d01930e7d01220cc48a22dffe30bfcbaf08a795140c7d040433b7ff3cba5f3e336a40060cecbd2bfaf775bea7bde7e095ee0cc4caaef7fb623feeaab69eabc20c8c0021bffd1ea4a1b090175a920c7d046445fbdfc1abe910b0ca56160c7d0440cbd7ef03893c7f7d02e1a8c20c85e42dff5fdaa145759d326b5a0ccc4084f75f8eeb7b15e4eb4ff80c6bc22ef7d7eaf8df3b8ff678cc0cca4026f3cf7518fd731ceca3560cec041ffbe7655eaf822f04c4fe0c7d0478e3fbfcb5dfc8a81fdbb9e20cc418e6d7ff777f26affe37cc020cd7977cbff7d0aecb9727be6a0c0c00bde1f2d797fc8754ed09d4ae0cc498279f7e729fcb9eff70c1a60c7d0478e5bfffc67eef953fda69aa0c7200f1bbf7e891ef5a287cb5b80c983629fee5555f739f8a29279a0c76d103bef73f55a6bf89ba8ce40cc46424f6ded9a194167a067d05880cc4780efeffc37fae944d89bfb40c4464bffffb6dd54e8344394a5c0c49781ffffc653feaa31af59ac00cc464cebfd76ae4e8a55d5b5a4a2a3738393436383035303034323639322a303033352a303434332a4a58544b2c302c77617463685f375f32303232303532363039333935342c322c362c5f24fbbc0c7d04983effcfe35fbd8fff7ce6f60c448a1dfbd715bec3b42448e58a0c0e0421bf5f17ebc31a43301bc40c768ababf4f66cf629ee31fe9900c6b6426bf5f4eb7669dacc439140c945733bff9351e7d04ab6be54ef60ccc98bfbffbf67f63b78d8f42880c7d0400c6f7fffab5cbae8e8275da0c0097ffdefff5dfafb0c4727d04980ccc78d1f6ff1a6b7e37631059fa0c760045f3fd853fea877d03aa87440cc40022f7ffa8b5c58f6e80c58e0ccc4c1f9ffff32fa7af87de04560cb09801f6fdd32efcbdad9495b60c6b987d05bff72d61eb687d05a9f9e20cca57c7ffff6cb1fe3387ea596e0c629823dedfbfc50b97965e44ea0c4918ccbfd7cc75e59fff92e9ee0c8c78e7faff707ffda60ec3ada60c30c217befffcb8f3290f06d75e0c0e8a7bb7dff3eec7b7928ef6680c38ca1cdeff272ba012597d051a520c0018dfffeff27d01e369b3bcd7d80c98146eb2fc7f45c38e1ce53e120c3d5700ff7fd44bee28aa089d900c007157bffffe30302d7d0583585c0ccc5747bfe7f73cff7d02de1098240c7d047865f6feca71d70bdfaab6a20cecb946bfd966be74b61a06c6660c441612ffe7eb966a8c2886cf760ccc7827bffd653ff7980a62e9320c00ca98f7fc1b311a3986700cc20c490017bfff70cfe7bb455637320c6228afbf7e6da4c59763b693740cccc2b5fee1951975760e4a9dca0c0000faffdb255f6f86af4be6fc0cccc2ffdfff7d0225efbc847c42760cb48a8fdffbe23ff1a78782cbe60c7d04980cffff6e6dfc75a6c65a500ce62808bfff24f853748a9537400cb4004ebfeb6e70aa4314903e8c0cb46408ff72d62f44945f64897d040cccca7abfff2db5c6bfcc345e700c7d04c24dd6fd5f95638f78974a800cc4caffffffb17d01c36bdd7d047c2e0c7d0436d1f7f8917f83af7fc5c2180c070449f6fe570f128577c8c97d040c7d047813f6df3fd17d026b6790d1b80cc400c9d6d92dc56497843ed10a0c44986effffe13fef8eef7c717a0c7d049872bbfdad3abe2be0d60b240c4900adbf7d02dfa4ef960fdf23580c629845fefc5a650fbf8b0d4cda0c7d040076b7ef273fe78fce983ae40c4a00ded7ff629f7fab4531501c0c6200b7ffedf13fe6a68f01fb6c0cc49809f77fdb91517fb39e8ba00c760009bf7fd6afe7b46921f27a0cecbd1df6faf99120776e807d03fe0c98ca23fbff3749fb5ed3909c160cc44cbbbfffbd70e77d0367bc2e740c499816f77fe2ffe08edd7d048c9e0c940021beff1df0f1338c2f1a3a0c7d040083feebba1c756e5760c2200c94981dfffdf921b92b99909ba40c7d04984ebbdf7ff0c77d025a1fbfc00c7657b3ff77f4befcae2bf625640c62ca53f7fdb35f2e92af3bd5c60c7d049878bbdfc0dfc1bdaa1918000cc404bbbfefb41ee6b50a39bf180c767874f7fb8ee156320ee600020c69981cffffe0fff6bb2764acaa0cec781bfbff7d0324eb9b4b4d5d5b5a4a2a3738393436383035303034323639322a303033362a303433302a4a58544b2c302c77617463685f375f32303232303532363039333935342c332c362c73580c07ca4fbbfff5bec5abcfac465c0c0042a8beff316aed38fe4603dc0c7d04577d04fefdc929f7294ce7520c0c76984dfaff402fe68ebe113b000c7d0436a6fed465ff4f8d8e3306300c44e434f7f79e84abb8fa081be80c983636bef7e128bf7d03d34c71c80cd7982dffd54cac94536beab1320c058bd6bfff701fe69d1a39d1e80c76caedb77ffea0e47febb469440c0098b2bef5e55eed981672b1c40cd800d1bef4bda58daf7d01d309180c08cadffbfc31799f5613fab2da0c7d049828beffa5eea0bd09a14c2e0c0000e59feb5f9dff7f4945e98e0cc40046ffcfe57fb58f7d053dd9e20c7d040047d7ffd38f67aa9db8d38c0c7698d2df5fe2efc6bb0f5a18220c980367bbfd95dae73e3bf2b59a0c49813796fdf5efab9d3ed7d3d80c9800ebd7fdb831ae8f91811e920c7d04ca74bbff5cdcf45605c25f140c013e029fbfe7ffc299376b409a0c7510009e7d02010f68824cccead60cb13b00f7d5821e6c8d594a06880c75ec00f6e782e8f06b0c610d1a0cc09843dfef117fa5b3aef236f40cdcc208ffff4831f83703ca20c00cc09800bf7fd71eec9ba34e3c200c650f6bffd5bc4dbe7ec5b0f1d80c0d1c1f92ef917fa0b96023eac00c8efb1db6bfa42eed9f69051d4e0c8eff23b2fe4486d56ef44f702e0c8ebc1b9657d46eeea852ac337e0c8efb1f96d9877fc9b34c38f1540c121c2796df13577c727f8cedec0ca9107d05afdd6a9d957ab76c02560c121c2dd6bfd33fa5b844f27d02340cb11037b6e3962e6eaf52d6e7460c2b1c3db2dfe61eef9aad3dcc0a0c542e42d763e709fe723a83ae7c0c7cfa56bf7fedb8763c3f8ab2c00ca40022efff2411604d22a485e00c228adcbfdfcd748293c66b0bf20cb10f0097ff806dcf7a0a640d6e0c5a0400b7e3030ef4ae0a6046f80cb82812fe7b04d77e4bab11894a0c541c24b2dd53fea5891e3824420ca9fb26b2d7156fa485049cac420ca91c2d9edb2487526c2e2260fa0ca9bc25b65ff28e41a34232c0f00c8efb25b649e51ec39c0ae6703a0c70f425a6c820dfaf2f8124c8960c80f42794b323aed9ca9b6924be0cb93b278e3e8d929c36bb70b6360c587b27524f85857d056d214841660cda2f278b4c876eb3186e5acc540ce6832f6e3f0d82f81226e6dc3a0c0b922feff50a03d03c98ae28360c03d62befb54ab611de0c8addee0c84d626b7fdb4461556dc0153040c0b0f27ff5781c5c2b32f6762140c49bf2dfaf521969b702ecb11d80c7d050f27cfed75bfab95dc4af3180c011c3d8e7451df80a5cd0948080c7c2e35f2c7b0becca22e50769e0c7c1c3d965e628f46a9a58ae6100c7c2e3b965f4a6b5ebd1436b0b00c7c863eaedf18c7816cdeeed7e20c2b3e3df6b73952b2b1abc048a00c7cfb3db6cd67ae68cda18af9d60c2bff3e96df12ff61b39627cd580c7c863fd6cd810ee595d85ee6645d5b5a4a2a3738393436383035303034323639322a303033372a303433372a4a58544b2c302c77617463685f375f32303232303532363039333935342c342c362c0c7cff3fb65f812fe196dc62d8360c7c2e3db2de738fae9ca7c7236c0c2b2e3d96df6c1d775a3df5a47e0c7c3e3f96fe943dc07e81e170700c75503fb7d6a6197f1b08df85440c5a133ab6d6a0e68f3acb04b7b00cfa293fd6cfc20c390d5265d3c80c581347b278077d03dc22d9e49c680ce64d47924e8dcdffe9be19dc100cb90f4f9e612d2201961c2e111c0c003b4febb58a96c809ab5a71040ce6d759fbddba54b2aa9d9d983e0cc029576ecf1f703099d84994520c4029579e7d0281577073f5629dd80c5a2952b6fed177177d01e57d0175c20cd8647d044f7e3c58aba523ddb0720cb56753d3e9c6799f95938401f60c756414ff5f00fb57bc4d7e111c0c7c085573ef743ee19ca30057e00c752e5ab77e34eec69f3cbe53940c542e4d96d6e7ff03854a9506620c7cff55b6efca197610a86606180c7cfb55b67eb25f4b999c002bf20c7c107d03beeb451fad8d042492740cb8f05eb5ff664f679c1cc991c60ce1671bffd33d9445b57d0584c7d60c07781dfef5e3ee81b45ff8a8c80cc40072b7dfe6fe6e978257253a0cb1131fe6783035868e439b00d80c583b27b17ecb53dd165c3422180c703b2fbeb18d023e14d90304700c3cce2b93cdc2e6b3550a5546160cb13b3b72fe24273859059b52040c224d34edc742f6bb7c877d02b5940cb84d37cdcfcbc3f03a041cf4ac0ca4923a9f3b74e805b235cce8660c759000fbfd90565072aa7d03bb520cb592017f411dcbe80a0cc420360c09d6528fcf2e25b382ee46d75a0ce2e853d3cfb617fd7d023f05e0780c07cc3bbabfa9f6cec5aa48ac600c404208fb678a4cf16a9c09098c0cf14244fbdfc2afe7932fe57d02900c011c369e7d0264a8570a54f9a2e80cb1103daed6249fe59dc888c2ac0cb1103573c5f697be759923ecc80c705f7d059effaaa4b09b976f375a0c804223bbed89767d041693edab180cb49819d7eb5a8573bb10c951540c3c643af74f021f25b6dd3b7d02040c07982bd73fb31fe38f09a227a40c037610ff7d03c6058098fef936a80c03b808debbe055a1a71319128c0c6b8f2e9e3bb52d71c226d3141a0cdab82d7fa9d416167a1cb950020c03c32bb23ee9e3743f3b6853060cc02937adb5157d05f4a6960c1b680c4076365e6b754bda9394a7aa720c06293ef23313fb1b94bcc2c09a0ce676006bbd8e0417941b90d23c0cb9294f7d01fd3d65748cf6d1cc220c03767d035e3a65e6f2514ab1db060ce6d965bf4035f65c79a9e4446a0ce62921dbf46457b56cd65f6c500c584d6bba7ea8166edd6cf7693a0cb939227bfca25f82a7c4202f2e0c06ce2b9a4f0d95f39eb43c22840c06901eef6fd15fe48f452000e00c62023afbffb269beba0ee0ac540ce6ec00f37b8139f2026e80f1440c22501dfe7d017d03ed8c3ff6803f240cc48ae3b7fd725e63a347cd64100c0094f8efdeb0a9f35c83eb06b00c005d5b5a4a2a3738393436383035303034323639322a303033382a303433332a4a58544b2c302c77617463685f375f32303232303532363039333935342c352c362c6647deef2df57fb68fd76b660c44e43cbfefc0beec867d025c3f920cb4507d01ff6f42ee6c1f58a0db0e0c7d045701ff7f19f9f90fdff037c20c4404259efcd47d02a52b7ef6df0e0c7d04d128f3578db14779993109560ce1e41ecffd2851af49256b1ecc0c7d049837ffff707168db3dd1ac240cc09419f7f39a7d013d6ec1b4e55c0cc4881cff5f49f55fadc52285a40c06ce9ad7dbb8349b97031ac3b00c407d049d9bed74dfadad950eab560c06799ffac7a924b18bdf11c3d40c8054a2f777522e65be921a77240c8042a19bff706fe5b7e3e7d0360cd82840bff3f4fe429bea0081560c0064419fd9157f8b9c797e92c20cc47fe2b7d5e6ee45bf0524010e0c0894299e7d037e4553bcbbc0989e0c40501bbbdc926f8daf53885e0a0c80971ffee559f5bf98ed54cf140c00581abbffac75b88b14d5e3780c5a046dd66fd7bfe5b7ca749df40c403672bbcfe47ee797860ded5e0cb5502efb7ee2ffc7bbdc27d0880c44ca08fbf7031ecd9321d21ef40cdc9806fefde36f0699ad1569420c22cb1bfbdc974fcb900ab601440c00cb1cfbdfd2f7d2730b0b46680c0b4203dfef309fe0adc121e2080c225829feeb901f25b926343bae0c624204dfff4875b69ceda4df4c0c499886ffe7301e8e8bf9ef0a260cdce408dbef829fe45337e98d860c010800ef76088d8015f3b2c84e0c755c3ecfc898f50fbcdb9344220c7c7d03459349337d01e4949da1b4ec0c7cf046ae6e4a90df3552070a5e0c7cf045d23fbba0951147986eca0c7536426e6ef2ef0b7d01c22fd2960cb8284e9db92d40552988334f200cb8024acdbfea90d13b545fe35e0cb8f04d5e48659d48b97c1096140c7c084f79df4402702126bf358a0cb8a74d4def66535e145638d12e0c543e4d8edfa2531b15a340eb800cb83e4eafbd9031291a8563e4780c54a74ef1c7300da79aa94bb67d050cb8f04eba6fb0325813871511b80ce20ff6fffd404ed58ecf264c8e0c7c0f1cb3fe1a36fb7187c379d00c7c3e52f6727d0261ca8bdd1361b80cb8d64d9a4fb1cfe0aadaaa7d05c40c2b2e44b2bfb9b4dcad9d7d0200280c7c3b47d5db803fc2aee71a77f00c7c1343b2bfa06ee6ad3228f10a0c7c3b4a76477fe7650b0c809ca80c54d74b92dbc327134514d6126e0c7c5f4a8f4f74efaaa5cd0a43bc0c7c104bb64ff5ce604fa2028b680c7cff4aaec7f7a9394cc4c599e60cb8ce52eeb553d215a6a466b4120c750f4fae5f9816c04a0a3f751e0c75e04f73c58e96bb4b925a4c680cb80f4b6e3fe1635614bbdeccbc0c7c3b4faf7e825e42d473ee76800ce298578ffcb61f0af936387bbe0cb800e39bf62410681583e0d2b20cb4987d05ff7f297bf69eaf4cd8b40cb57815bf7f300fcffe9fae966a0cb497acd75fd37f648d00d141a00cc48af9fffe1a3b979b8f8573e80c29bff1bf4b94c6fd7c3eec075e0c7cce1f5d5b5a4a2a3738393436383035303034323639322a303033392a303065352a4a58544b2c302c77617463685f375f32303232303532363039333935342c362c362c8f5cf9f34fa6edceb18c0ca4ce436e7d02d329de94b63eb11a0cb894438f44cf753dbc1a83b4560cb8e44391eff729d4155a231bf40cb59443f373b4288492cd6e38160c5a42049bfec8678ad42bce0c560cb12e39fec3d1fe24b5572ee0be0cb1ce35fe33688455aa74e3ffa40cb1d635df4b704160ae864a7d03440cb10f3267dbf4a21d540ca1051c0cb11337724f8747f5547d054e91660cb1a73692df964f3bbb0758d41a0cfe05b60c314460297eae4185f20cad673ceb6dfa05ddbe0278d5de5d"));
https://github.com/traccar/traccar.gitdiff --git a/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java b/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java
gitbug-java_data_traccar-traccar.json_4
diff --git a/src/main/java/org/traccar/protocol/GalileoProtocolDecoder.java b/src/main/java/org/traccar/protocol/GalileoProtocolDecoder.java index b5c6f77..d4bd45c 100644 --- a/src/main/java/org/traccar/protocol/GalileoProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/GalileoProtocolDecoder.java @@ -272,10 +272,10 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { private Position decodeIridiumPosition(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { - buf.readUnsignedShortLE(); // length + buf.readUnsignedShort(); // length buf.skipBytes(3); // identification header - buf.readUnsignedIntLE(); // index + buf.readUnsignedInt(); // index DeviceSession deviceSession = getDeviceSession( channel, remoteAddress, buf.readSlice(15).toString(StandardCharsets.US_ASCII)); @@ -288,12 +288,19 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedByte(); // session status buf.skipBytes(4); // reserved - buf.readUnsignedIntLE(); // date and time - - buf.skipBytes(23); // coordinates block - - buf.skipBytes(3); // data tag header - decodeMinimalDataSet(position, buf); + position.setTime(new Date(buf.readUnsignedInt() * 1000)); + + buf.skipBytes(3); // coordinates header + int flags = buf.readUnsignedByte(); + double latitude = buf.readUnsignedByte() + buf.readUnsignedShort() / 60000.0; + double longitude = buf.readUnsignedByte() + buf.readUnsignedShort() / 60000.0; + position.setLatitude(BitUtil.check(flags, 1) ? -latitude : latitude); + position.setLongitude(BitUtil.check(flags, 0) ? -longitude : longitude); + buf.readUnsignedInt(); // accuracy + + buf.readUnsignedByte(); // data tag header + // ByteBuf data = buf.readSlice(buf.readUnsignedShort()); + // decodeMinimalDataSet(position, data); return position; } diff --git a/src/test/java/org/traccar/protocol/GalileoProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/GalileoProtocolDecoderTest.java index 8c08fee..df7f379 100644 --- a/src/test/java/org/traccar/protocol/GalileoProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/GalileoProtocolDecoderTest.java @@ -10,7 +10,7 @@ public class GalileoProtocolDecoderTest extends ProtocolTest { var decoder = inject(new GalileoProtocolDecoder(null)); - verifyNotNull(decoder, binary( + verifyPosition(decoder, binary( "01004e01001c0747ea59333030323334303639363034353930000012000063c85e6903000b0321a8f846aba50000000202001e205f5ec863300c4643fdfdbbe6c8fb330000000034e7013505d400000000")); verifyNotNull(decoder, binary(
https://github.com/traccar/traccar.gitdiff --git a/src/main/java/org/traccar/protocol/GalileoProtocolDecoder.java b/src/main/java/org/traccar/protocol/GalileoProtocolDecoder.java
gitbug-java_data_traccar-traccar.json_5
diff --git a/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java b/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java index 6fb626d..e100d0d 100644 --- a/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java @@ -139,41 +139,45 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { String[] values = parser.next().split(","); int index = 0; - Network network = new Network(); - - int cellCount = Integer.parseInt(values[index++]); - if (cellCount > 0) { - index += 1; // timing advance - int mcc = !values[index].isEmpty() ? Integer.parseInt(values[index++]) : 0; - int mnc = !values[index].isEmpty() ? Integer.parseInt(values[index++]) : 0; - - for (int i = 0; i < cellCount; i++) { - int lac = Integer.parseInt(values[index++]); - int cid = Integer.parseInt(values[index++]); - String rssi = values[index++]; - if (!rssi.isEmpty()) { - network.addCellTower(CellTower.from(mcc, mnc, lac, cid, Integer.parseInt(rssi))); - } else { - network.addCellTower(CellTower.from(mcc, mnc, lac, cid)); + if (values.length < 4 || !values[index + 3].startsWith("F")) { + + Network network = new Network(); + + int cellCount = Integer.parseInt(values[index++]); + if (cellCount > 0) { + index += 1; // timing advance + int mcc = !values[index].isEmpty() ? Integer.parseInt(values[index++]) : 0; + int mnc = !values[index].isEmpty() ? Integer.parseInt(values[index++]) : 0; + + for (int i = 0; i < cellCount; i++) { + int lac = Integer.parseInt(values[index++]); + int cid = Integer.parseInt(values[index++]); + String rssi = values[index++]; + if (!rssi.isEmpty()) { + network.addCellTower(CellTower.from(mcc, mnc, lac, cid, Integer.parseInt(rssi))); + } else { + network.addCellTower(CellTower.from(mcc, mnc, lac, cid)); + } } } - } - if (index < values.length && !values[index].isEmpty()) { - int wifiCount = Integer.parseInt(values[index++]); + if (index < values.length && !values[index].isEmpty()) { + int wifiCount = Integer.parseInt(values[index++]); - for (int i = 0; i < wifiCount; i++) { - index += 1; // wifi name - String macAddress = values[index++]; - String rssi = values[index++]; - if (!macAddress.isEmpty() && !macAddress.equals("0") && !rssi.isEmpty()) { - network.addWifiAccessPoint(WifiAccessPoint.from(macAddress, Integer.parseInt(rssi))); + for (int i = 0; i < wifiCount; i++) { + index += 1; // wifi name + String macAddress = values[index++]; + String rssi = values[index++]; + if (!macAddress.isEmpty() && !macAddress.equals("0") && !rssi.isEmpty()) { + network.addWifiAccessPoint(WifiAccessPoint.from(macAddress, Integer.parseInt(rssi))); + } } } - } - if (network.getCellTowers() != null || network.getWifiAccessPoints() != null) { - position.setNetwork(network); + if (network.getCellTowers() != null || network.getWifiAccessPoints() != null) { + position.setNetwork(network); + } + } return position; diff --git a/src/test/java/org/traccar/protocol/WatchProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/WatchProtocolDecoderTest.java index 0ffe819..09dd461 100644 --- a/src/test/java/org/traccar/protocol/WatchProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/WatchProtocolDecoderTest.java @@ -17,6 +17,9 @@ public class WatchProtocolDecoderTest extends ProtocolTest { var decoder = inject(new WatchProtocolDecoder(null)); + verifyPosition(decoder, buffer( + "[SG*9059011020*006b*UD2,240123,162011,A,54.427621,N,6.409190,W,0.00,0,0,8,19,88,0,0,00000000,1,1,FFFF,FFFF,FFFE,3B882A2,132,,00]")); + verifyAttribute(decoder, buffer( "[ZJ*5678901234*0001*0009*TEMP,36.5]"), Position.PREFIX_TEMP + 1, 36.5);
https://github.com/traccar/traccar.gitdiff --git a/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java b/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java
gitbug-java_data_traccar-traccar.json_6
diff --git a/src/main/java/org/traccar/helper/StringUtil.java b/src/main/java/org/traccar/helper/StringUtil.java new file mode 100644 index 0000000..9b4d717 --- a/src/main/java/org/traccar/helper/StringUtil.java +++ b/src/main/java/org/traccar/helper/StringUtil.java @@ -0,0 +1,32 @@ +/* + * Copyright 2023 Anton Tananaev ([email protected]) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.helper; + +public final class StringUtil { + + private StringUtil() { + } + + public static boolean containsHex(String value) { + for (char c : value.toCharArray()) { + if (c >= 'a' && c <= 'f' || c >= 'A' && c <= 'F') { + return true; + } + } + return false; + } + +} diff --git a/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java b/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java index e100d0d..40d56b1 100644 --- a/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 - 2022 Anton Tananaev ([email protected]) + * Copyright 2015 - 2023 Anton Tananaev ([email protected]) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; +import org.traccar.helper.StringUtil; import org.traccar.session.DeviceSession; import org.traccar.NetworkMessage; import org.traccar.Protocol; @@ -139,7 +140,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { String[] values = parser.next().split(","); int index = 0; - if (values.length < 4 || !values[index + 3].startsWith("F")) { + if (values.length < 4 || !StringUtil.containsHex(values[index + 3])) { Network network = new Network(); @@ -150,8 +151,8 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { int mnc = !values[index].isEmpty() ? Integer.parseInt(values[index++]) : 0; for (int i = 0; i < cellCount; i++) { - int lac = Integer.parseInt(values[index++]); - int cid = Integer.parseInt(values[index++]); + int lac = Integer.parseInt(values[index], StringUtil.containsHex(values[index++]) ? 16 : 10); + int cid = Integer.parseInt(values[index], StringUtil.containsHex(values[index++]) ? 16 : 10); String rssi = values[index++]; if (!rssi.isEmpty()) { network.addCellTower(CellTower.from(mcc, mnc, lac, cid, Integer.parseInt(rssi))); diff --git a/src/test/java/org/traccar/protocol/WatchProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/WatchProtocolDecoderTest.java index 09dd461..37fab7e 100644 --- a/src/test/java/org/traccar/protocol/WatchProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/WatchProtocolDecoderTest.java @@ -18,6 +18,9 @@ public class WatchProtocolDecoderTest extends ProtocolTest { var decoder = inject(new WatchProtocolDecoder(null)); verifyPosition(decoder, buffer( + "[SG*9059011020*0067*AL,240123,181628,V,54.427538,N,6.409275,W,0.00,0,0,0,19,90,0,0,00000000,1,1,234,10,55C0,3B882A2,132,,10]")); + + verifyPosition(decoder, buffer( "[SG*9059011020*006b*UD2,240123,162011,A,54.427621,N,6.409190,W,0.00,0,0,8,19,88,0,0,00000000,1,1,FFFF,FFFF,FFFE,3B882A2,132,,00]")); verifyAttribute(decoder, buffer(
https://github.com/traccar/traccar.gitdiff --git a/src/main/java/org/traccar/helper/StringUtil.java b/src/main/java/org/traccar/helper/StringUtil.java
gitbug-java_data_traccar-traccar.json_7
diff --git a/src/main/java/org/traccar/api/resource/CommandResource.java b/src/main/java/org/traccar/api/resource/CommandResource.java index 6ef6ee9..3460cf6 100644 --- a/src/main/java/org/traccar/api/resource/CommandResource.java +++ b/src/main/java/org/traccar/api/resource/CommandResource.java @@ -105,7 +105,6 @@ public class CommandResource extends ExtendedObjectResource<Command> { @POST @Path("send") public Response send(Command entity) throws Exception { - permissionsService.checkRestriction(getUserId(), UserRestrictions::getReadonly); if (entity.getId() > 0) { permissionsService.checkPermission(baseClass, getUserId(), entity.getId()); long deviceId = entity.getDeviceId(); diff --git a/src/main/java/org/traccar/api/resource/ReportResource.java b/src/main/java/org/traccar/api/resource/ReportResource.java index 70177dd..6944de9 100644 --- a/src/main/java/org/traccar/api/resource/ReportResource.java +++ b/src/main/java/org/traccar/api/resource/ReportResource.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 - 2022 Anton Tananaev ([email protected]) + * Copyright 2016 - 2023 Anton Tananaev ([email protected]) * Copyright 2016 - 2018 Andrey Kunitsyn ([email protected]) * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,27 +19,23 @@ package org.traccar.api.resource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.traccar.api.BaseResource; -import org.traccar.mail.MailManager; import org.traccar.helper.LogAction; import org.traccar.model.Event; import org.traccar.model.Position; -import org.traccar.model.User; import org.traccar.model.UserRestrictions; import org.traccar.reports.EventsReportProvider; import org.traccar.reports.RouteReportProvider; import org.traccar.reports.StopsReportProvider; import org.traccar.reports.SummaryReportProvider; import org.traccar.reports.TripsReportProvider; +import org.traccar.reports.common.ReportExecutor; +import org.traccar.reports.common.ReportMailer; import org.traccar.reports.model.StopReportItem; import org.traccar.reports.model.SummaryReportItem; import org.traccar.reports.model.TripReportItem; import org.traccar.storage.StorageException; -import javax.activation.DataHandler; import javax.inject.Inject; -import javax.mail.MessagingException; -import javax.mail.internet.MimeBodyPart; -import javax.mail.util.ByteArrayDataSource; import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.Path; @@ -51,9 +47,6 @@ import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.StreamingOutput; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.OutputStream; import java.util.Collection; import java.util.Date; import java.util.List; @@ -83,31 +76,11 @@ public class ReportResource extends BaseResource { private TripsReportProvider tripsReportProvider; @Inject - private MailManager mailManager; + private ReportMailer reportMailer; - private interface ReportExecutor { - void execute(OutputStream stream) throws StorageException, IOException; - } - - private Response executeReport( - long userId, boolean mail, ReportExecutor executor) { + private Response executeReport(long userId, boolean mail, ReportExecutor executor) { if (mail) { - new Thread(() -> { - try { - var stream = new ByteArrayOutputStream(); - executor.execute(stream); - - MimeBodyPart attachment = new MimeBodyPart(); - attachment.setFileName("report.xlsx"); - attachment.setDataHandler(new DataHandler(new ByteArrayDataSource( - stream.toByteArray(), "application/octet-stream"))); - - User user = permissionsService.getUser(userId); - mailManager.sendMessage(user, "Report", "The report is in the attachment.", attachment); - } catch (StorageException | IOException | MessagingException e) { - LOGGER.warn("Report failed", e); - } - }).start(); + reportMailer.sendAsync(userId, executor); return Response.noContent().build(); } else { StreamingOutput stream = output -> { diff --git a/src/main/java/org/traccar/handler/ComputedAttributesHandler.java b/src/main/java/org/traccar/handler/ComputedAttributesHandler.java index c9f1f63..6208525 100644 --- a/src/main/java/org/traccar/handler/ComputedAttributesHandler.java +++ b/src/main/java/org/traccar/handler/ComputedAttributesHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2022 Anton Tananaev ([email protected]) + * Copyright 2017 - 2023 Anton Tananaev ([email protected]) * Copyright 2017 Andrey Kunitsyn ([email protected]) * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -116,17 +116,45 @@ public class ComputedAttributesHandler extends BaseDataHandler { } if (result != null) { try { - switch (attribute.getType()) { - case "number": - Number numberValue = (Number) result; - position.getAttributes().put(attribute.getAttribute(), numberValue); + switch (attribute.getAttribute()) { + case "valid": + position.setValid((Boolean) result); break; - case "boolean": - Boolean booleanValue = (Boolean) result; - position.getAttributes().put(attribute.getAttribute(), booleanValue); + case "latitude": + position.setLatitude(((Number) result).doubleValue()); + break; + case "longitude": + position.setLongitude(((Number) result).doubleValue()); + break; + case "altitude": + position.setAltitude(((Number) result).doubleValue()); + break; + case "speed": + position.setSpeed(((Number) result).doubleValue()); + break; + case "course": + position.setCourse(((Number) result).doubleValue()); + break; + case "address": + position.setAddress((String) result); + break; + case "accuracy": + position.setAccuracy(((Number) result).doubleValue()); break; default: - position.getAttributes().put(attribute.getAttribute(), result.toString()); + switch (attribute.getType()) { + case "number": + Number numberValue = (Number) result; + position.getAttributes().put(attribute.getAttribute(), numberValue); + break; + case "boolean": + Boolean booleanValue = (Boolean) result; + position.getAttributes().put(attribute.getAttribute(), booleanValue); + break; + default: + position.getAttributes().put(attribute.getAttribute(), result.toString()); + } + break; } } catch (ClassCastException error) { LOGGER.warn("Attribute cast error", error); diff --git a/src/main/java/org/traccar/helper/ClassScanner.java b/src/main/java/org/traccar/helper/ClassScanner.java index c928f6a..c201d10 100644 --- a/src/main/java/org/traccar/helper/ClassScanner.java +++ b/src/main/java/org/traccar/helper/ClassScanner.java @@ -46,7 +46,7 @@ public final class ClassScanner { URL packageUrl = baseClass.getClassLoader().getResource(packagePath); if (packageUrl.getProtocol().equals("jar")) { - String jarFileName = URLDecoder.decode(packageUrl.getFile(), StandardCharsets.UTF_8.name()); + String jarFileName = URLDecoder.decode(packageUrl.getFile(), StandardCharsets.UTF_8); try (JarFile jf = new JarFile(jarFileName.substring(5, jarFileName.indexOf("!")))) { Enumeration<JarEntry> jarEntries = jf.entries(); while (jarEntries.hasMoreElements()) { diff --git a/src/main/java/org/traccar/helper/StringUtil.java b/src/main/java/org/traccar/helper/StringUtil.java new file mode 100644 index 0000000..9b4d717 --- a/src/main/java/org/traccar/helper/StringUtil.java +++ b/src/main/java/org/traccar/helper/StringUtil.java @@ -0,0 +1,32 @@ +/* + * Copyright 2023 Anton Tananaev ([email protected]) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.helper; + +public final class StringUtil { + + private StringUtil() { + } + + public static boolean containsHex(String value) { + for (char c : value.toCharArray()) { + if (c >= 'a' && c <= 'f' || c >= 'A' && c <= 'F') { + return true; + } + } + return false; + } + +} diff --git a/src/main/java/org/traccar/model/Report.java b/src/main/java/org/traccar/model/Report.java new file mode 100644 index 0000000..83bb2e9 --- a/src/main/java/org/traccar/model/Report.java +++ b/src/main/java/org/traccar/model/Report.java @@ -0,0 +1,65 @@ +/* + * Copyright 2022 Anton Tananaev ([email protected]) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.model; + +import org.traccar.storage.StorageName; + +import java.util.Date; + +@StorageName("tc_reports") +public class Report extends ScheduledModel { + + private String type; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + private String description; + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + private Date from; + + public Date getFrom() { + return from; + } + + public void setFrom(Date from) { + this.from = from; + } + + private Date to; + + public Date getTo() { + return to; + } + + public void setTo(Date to) { + this.to = to; + } + +} diff --git a/src/main/java/org/traccar/protocol/GalileoProtocolDecoder.java b/src/main/java/org/traccar/protocol/GalileoProtocolDecoder.java index fc8a49c..d4bd45c 100644 --- a/src/main/java/org/traccar/protocol/GalileoProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/GalileoProtocolDecoder.java @@ -23,6 +23,7 @@ import org.traccar.BaseProtocolDecoder; import org.traccar.NetworkMessage; import org.traccar.Protocol; import org.traccar.helper.BitBuffer; +import org.traccar.helper.BitUtil; import org.traccar.helper.UnitsConverter; import org.traccar.model.Position; import org.traccar.session.DeviceSession; @@ -66,7 +67,7 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { }; int[] l3 = { 0x63, 0x64, 0x6f, 0x5d, 0x65, 0x66, 0x67, 0x68, - 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e + 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0xfa }; int[] l4 = { 0x20, 0x33, 0x44, 0x90, 0xc0, 0xc2, 0xc3, 0xd3, @@ -88,6 +89,8 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { } TAG_LENGTH_MAP.put(0x5b, 7); // variable length TAG_LENGTH_MAP.put(0x5c, 68); + TAG_LENGTH_MAP.put(0xfd, 8); + TAG_LENGTH_MAP.put(0xfe, 8); } private static int getTagLength(int tag) { @@ -239,6 +242,8 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { } } else if (header == 0x07) { return decodePhoto(channel, remoteAddress, buf); + } else if (header == 0x08) { + return decodeCompressedPositions(channel, remoteAddress, buf); } return null; @@ -259,7 +264,7 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { position.setValid(bits.readUnsigned(1) == 0); position.setLongitude(360 * bits.readUnsigned(22) / 4194304.0 - 180); - position.setLatitude(360 * bits.readUnsigned(21) / 2097152.0 - 90); + position.setLatitude(180 * bits.readUnsigned(21) / 2097152.0 - 90); if (bits.readUnsigned(1) > 0) { position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); } @@ -267,10 +272,10 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { private Position decodeIridiumPosition(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { - buf.readUnsignedShortLE(); // length + buf.readUnsignedShort(); // length buf.skipBytes(3); // identification header - buf.readUnsignedIntLE(); // index + buf.readUnsignedInt(); // index DeviceSession deviceSession = getDeviceSession( channel, remoteAddress, buf.readSlice(15).toString(StandardCharsets.US_ASCII)); @@ -283,12 +288,19 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedByte(); // session status buf.skipBytes(4); // reserved - buf.readUnsignedIntLE(); // date and time + position.setTime(new Date(buf.readUnsignedInt() * 1000)); - buf.skipBytes(23); // coordinates block + buf.skipBytes(3); // coordinates header + int flags = buf.readUnsignedByte(); + double latitude = buf.readUnsignedByte() + buf.readUnsignedShort() / 60000.0; + double longitude = buf.readUnsignedByte() + buf.readUnsignedShort() / 60000.0; + position.setLatitude(BitUtil.check(flags, 1) ? -latitude : latitude); + position.setLongitude(BitUtil.check(flags, 0) ? -longitude : longitude); + buf.readUnsignedInt(); // accuracy - buf.skipBytes(3); // data tag header - decodeMinimalDataSet(position, buf); + buf.readUnsignedByte(); // data tag header + // ByteBuf data = buf.readSlice(buf.readUnsignedShort()); + // decodeMinimalDataSet(position, data); return position; } @@ -392,4 +404,43 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { return position; } + private List<Position> decodeCompressedPositions(Channel channel, SocketAddress remoteAddress, ByteBuf buf) { + + buf.readUnsignedShortLE(); // length + + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress); + if (deviceSession == null) { + return null; + } + + List<Position> positions = new LinkedList<>(); + while (buf.readableBytes() > 2) { + + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + decodeMinimalDataSet(position, buf); + + int[] tags = new int[BitUtil.to(buf.readUnsignedByte(), 8)]; + for (int i = 0; i < tags.length; i++) { + tags[i] = buf.readUnsignedByte(); + } + + for (int tag : tags) { + decodeTag(position, buf, tag); + } + + positions.add(position); + + } + + sendResponse(channel, 0x02, buf.readUnsignedShortLE()); + + for (Position p : positions) { + p.setDeviceId(deviceSession.getDeviceId()); + } + + return positions.isEmpty() ? null : positions; + } + } diff --git a/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java b/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java index 142d1b6..40d56b1 100644 --- a/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/WatchProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 - 2022 Anton Tananaev ([email protected]) + * Copyright 2015 - 2023 Anton Tananaev ([email protected]) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; +import org.traccar.helper.StringUtil; import org.traccar.session.DeviceSession; import org.traccar.NetworkMessage; import org.traccar.Protocol; @@ -139,41 +140,45 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { String[] values = parser.next().split(","); int index = 0; - Network network = new Network(); + if (values.length < 4 || !StringUtil.containsHex(values[index + 3])) { - int cellCount = Integer.parseInt(values[index++]); - if (cellCount > 0) { - index += 1; // timing advance - int mcc = !values[index].isEmpty() ? Integer.parseInt(values[index++]) : 0; - int mnc = !values[index].isEmpty() ? Integer.parseInt(values[index++]) : 0; + Network network = new Network(); - for (int i = 0; i < cellCount; i++) { - int lac = Integer.parseInt(values[index++]); - int cid = Integer.parseInt(values[index++]); - String rssi = values[index++]; - if (!rssi.isEmpty()) { - network.addCellTower(CellTower.from(mcc, mnc, lac, cid, Integer.parseInt(rssi))); - } else { - network.addCellTower(CellTower.from(mcc, mnc, lac, cid)); + int cellCount = Integer.parseInt(values[index++]); + if (cellCount > 0) { + index += 1; // timing advance + int mcc = !values[index].isEmpty() ? Integer.parseInt(values[index++]) : 0; + int mnc = !values[index].isEmpty() ? Integer.parseInt(values[index++]) : 0; + + for (int i = 0; i < cellCount; i++) { + int lac = Integer.parseInt(values[index], StringUtil.containsHex(values[index++]) ? 16 : 10); + int cid = Integer.parseInt(values[index], StringUtil.containsHex(values[index++]) ? 16 : 10); + String rssi = values[index++]; + if (!rssi.isEmpty()) { + network.addCellTower(CellTower.from(mcc, mnc, lac, cid, Integer.parseInt(rssi))); + } else { + network.addCellTower(CellTower.from(mcc, mnc, lac, cid)); + } } } - } - if (index < values.length && !values[index].isEmpty()) { - int wifiCount = Integer.parseInt(values[index++]); + if (index < values.length && !values[index].isEmpty()) { + int wifiCount = Integer.parseInt(values[index++]); - for (int i = 0; i < wifiCount; i++) { - index += 1; // wifi name - String macAddress = values[index++]; - String rssi = values[index++]; - if (!macAddress.isEmpty() && !macAddress.equals("0") && !rssi.isEmpty()) { - network.addWifiAccessPoint(WifiAccessPoint.from(macAddress, Integer.parseInt(rssi))); + for (int i = 0; i < wifiCount; i++) { + index += 1; // wifi name + String macAddress = values[index++]; + String rssi = values[index++]; + if (!macAddress.isEmpty() && !macAddress.equals("0") && !rssi.isEmpty()) { + network.addWifiAccessPoint(WifiAccessPoint.from(macAddress, Integer.parseInt(rssi))); + } } } - } - if (network.getCellTowers() != null || network.getWifiAccessPoints() != null) { - position.setNetwork(network); + if (network.getCellTowers() != null || network.getWifiAccessPoints() != null) { + position.setNetwork(network); + } + } return position; @@ -263,7 +268,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { Position position = decodePosition(deviceSession, buf.toString(StandardCharsets.US_ASCII)); if (type.startsWith("AL")) { - if (position != null) { + if (position != null && !position.hasAttribute(Position.KEY_ALARM)) { position.set(Position.KEY_ALARM, Position.ALARM_GENERAL); } sendResponse(channel, id, index, "AL"); @@ -279,6 +284,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { || type.equalsIgnoreCase("HEART") || type.equalsIgnoreCase("BLOOD") || type.equalsIgnoreCase("BPHRT") + || type.equalsIgnoreCase("TEMP") || type.equalsIgnoreCase("btemp2")) { if (buf.isReadable()) { @@ -291,7 +297,9 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { String[] values = buf.toString(StandardCharsets.US_ASCII).split(","); int valueIndex = 0; - if (type.equalsIgnoreCase("btemp2")) { + if (type.equalsIgnoreCase("TEMP")) { + position.set(Position.PREFIX_TEMP + 1, Double.parseDouble(values[valueIndex])); + } else if (type.equalsIgnoreCase("btemp2")) { if (Integer.parseInt(values[valueIndex++]) > 0) { position.set(Position.PREFIX_TEMP + 1, Double.parseDouble(values[valueIndex])); } diff --git a/src/main/java/org/traccar/reports/common/ReportExecutor.java b/src/main/java/org/traccar/reports/common/ReportExecutor.java new file mode 100644 index 0000000..aed4b8c --- a/src/main/java/org/traccar/reports/common/ReportExecutor.java +++ b/src/main/java/org/traccar/reports/common/ReportExecutor.java @@ -0,0 +1,25 @@ +/* + * Copyright 2023 Anton Tananaev ([email protected]) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.reports.common; + +import org.traccar.storage.StorageException; + +import java.io.IOException; +import java.io.OutputStream; + +public interface ReportExecutor { + void execute(OutputStream stream) throws StorageException, IOException; +} diff --git a/src/main/java/org/traccar/reports/common/ReportMailer.java b/src/main/java/org/traccar/reports/common/ReportMailer.java new file mode 100644 index 0000000..1723c0e --- a/src/main/java/org/traccar/reports/common/ReportMailer.java +++ b/src/main/java/org/traccar/reports/common/ReportMailer.java @@ -0,0 +1,69 @@ +/* + * Copyright 2023 Anton Tananaev ([email protected]) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.reports.common; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.traccar.mail.MailManager; +import org.traccar.model.User; +import org.traccar.storage.Storage; +import org.traccar.storage.StorageException; +import org.traccar.storage.query.Columns; +import org.traccar.storage.query.Condition; +import org.traccar.storage.query.Request; + +import javax.activation.DataHandler; +import javax.inject.Inject; +import javax.mail.MessagingException; +import javax.mail.internet.MimeBodyPart; +import javax.mail.util.ByteArrayDataSource; +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +public class ReportMailer { + + private static final Logger LOGGER = LoggerFactory.getLogger(ReportMailer.class); + + private final Storage storage; + private final MailManager mailManager; + + @Inject + public ReportMailer(Storage storage, MailManager mailManager) { + this.storage = storage; + this.mailManager = mailManager; + } + + public void sendAsync(long userId, ReportExecutor executor) { + new Thread(() -> { + try { + var stream = new ByteArrayOutputStream(); + executor.execute(stream); + + MimeBodyPart attachment = new MimeBodyPart(); + attachment.setFileName("report.xlsx"); + attachment.setDataHandler(new DataHandler(new ByteArrayDataSource( + stream.toByteArray(), "application/octet-stream"))); + + User user = storage.getObject( + User.class, new Request(new Columns.All(), new Condition.Equals("id", userId))); + mailManager.sendMessage(user, "Report", "The report is in the attachment.", attachment); + } catch (StorageException | IOException | MessagingException e) { + LOGGER.warn("Email report failed", e); + } + }).start(); + } + +} diff --git a/src/main/java/org/traccar/schedule/ScheduleManager.java b/src/main/java/org/traccar/schedule/ScheduleManager.java index 6412a18..e1de3b3 100644 --- a/src/main/java/org/traccar/schedule/ScheduleManager.java +++ b/src/main/java/org/traccar/schedule/ScheduleManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 - 2022 Anton Tananaev ([email protected]) + * Copyright 2020 - 2023 Anton Tananaev ([email protected]) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,8 +38,12 @@ public class ScheduleManager implements LifecycleObject { @Override public void start() { executor = Executors.newSingleThreadScheduledExecutor(); - List.of(TaskDeviceInactivityCheck.class, TaskWebSocketKeepalive.class, TaskHealthCheck.class) - .forEach(task -> injector.getInstance(task).schedule(executor)); + var tasks = List.of( + TaskReports.class, + TaskDeviceInactivityCheck.class, + TaskWebSocketKeepalive.class, + TaskHealthCheck.class); + tasks.forEach(task -> injector.getInstance(task).schedule(executor)); } @Override diff --git a/src/main/java/org/traccar/schedule/TaskReports.java b/src/main/java/org/traccar/schedule/TaskReports.java new file mode 100644 index 0000000..259eb10 --- a/src/main/java/org/traccar/schedule/TaskReports.java +++ b/src/main/java/org/traccar/schedule/TaskReports.java @@ -0,0 +1,154 @@ +/* + * Copyright 2023 Anton Tananaev ([email protected]) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.schedule; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.traccar.model.BaseModel; +import org.traccar.model.Calendar; +import org.traccar.model.Device; +import org.traccar.model.Group; +import org.traccar.model.Report; +import org.traccar.model.User; +import org.traccar.reports.EventsReportProvider; +import org.traccar.reports.RouteReportProvider; +import org.traccar.reports.StopsReportProvider; +import org.traccar.reports.SummaryReportProvider; +import org.traccar.reports.TripsReportProvider; +import org.traccar.reports.common.ReportMailer; +import org.traccar.storage.Storage; +import org.traccar.storage.StorageException; +import org.traccar.storage.query.Columns; +import org.traccar.storage.query.Condition; +import org.traccar.storage.query.Request; + +import javax.inject.Inject; +import java.util.Date; +import java.util.List; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +public class TaskReports implements ScheduleTask { + + private static final Logger LOGGER = LoggerFactory.getLogger(TaskReports.class); + + private static final long CHECK_PERIOD_MINUTES = 1; + + private final Storage storage; + private final ReportMailer reportMailer; + + @Inject + private EventsReportProvider eventsReportProvider; + + @Inject + private RouteReportProvider routeReportProvider; + + @Inject + private StopsReportProvider stopsReportProvider; + + @Inject + private SummaryReportProvider summaryReportProvider; + + @Inject + private TripsReportProvider tripsReportProvider; + + @Inject + public TaskReports(Storage storage, ReportMailer reportMailer) { + this.storage = storage; + this.reportMailer = reportMailer; + } + + @Override + public void schedule(ScheduledExecutorService executor) { + executor.scheduleAtFixedRate(this, CHECK_PERIOD_MINUTES, CHECK_PERIOD_MINUTES, TimeUnit.MINUTES); + } + + @Override + public void run() { + Date currentCheck = new Date(); + Date lastCheck = new Date(System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(CHECK_PERIOD_MINUTES)); + + try { + for (Report report : storage.getObjects(Report.class, new Request(new Columns.All()))) { + Calendar calendar = storage.getObject(Calendar.class, new Request( + new Columns.All(), new Condition.Equals("id", report.getCalendarId()))); + if (calendar.checkMoment(currentCheck) && !calendar.checkMoment(lastCheck)) { + executeReport(report); + } + } + } catch (StorageException e) { + LOGGER.warn("Scheduled reports error", e); + } + } + + private void executeReport(Report report) throws StorageException { + var deviceIds = storage.getObjects(Device.class, new Request( + new Columns.Include("id"), + new Condition.Permission(Device.class, Report.class, report.getId()))) + .stream().map(BaseModel::getId).collect(Collectors.toList()); + var groupIds = storage.getObjects(Group.class, new Request( + new Columns.Include("id"), + new Condition.Permission(Group.class, Report.class, report.getId()))) + .stream().map(BaseModel::getId).collect(Collectors.toList()); + var users = storage.getObjects(User.class, new Request( + new Columns.Include("id"), + new Condition.Permission(User.class, Report.class, report.getId()))); + for (User user : users) { + switch (report.getType()) { + case "events": + reportMailer.sendAsync(user.getId(), stream -> { + eventsReportProvider.getExcel( + stream, user.getId(), deviceIds, groupIds, + List.of(), report.getFrom(), report.getTo()); + }); + break; + case "route": + reportMailer.sendAsync(user.getId(), stream -> { + routeReportProvider.getExcel( + stream, user.getId(), deviceIds, groupIds, + report.getFrom(), report.getTo()); + }); + break; + case "summary": + reportMailer.sendAsync(user.getId(), stream -> { + summaryReportProvider.getExcel( + stream, user.getId(), deviceIds, groupIds, + report.getFrom(), report.getTo(), false); + }); + break; + case "trips": + reportMailer.sendAsync(user.getId(), stream -> { + tripsReportProvider.getExcel( + stream, user.getId(), deviceIds, groupIds, + report.getFrom(), report.getTo()); + }); + break; + case "stops": + reportMailer.sendAsync(user.getId(), stream -> { + stopsReportProvider.getExcel( + stream, user.getId(), deviceIds, groupIds, + report.getFrom(), report.getTo()); + }); + break; + default: + LOGGER.warn("Unsupported report type {}", report.getType()); + break; + } + } + } + +} diff --git a/src/test/java/org/traccar/protocol/GalileoProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/GalileoProtocolDecoderTest.java index f676b1c..df7f379 100644 --- a/src/test/java/org/traccar/protocol/GalileoProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/GalileoProtocolDecoderTest.java @@ -10,6 +10,9 @@ public class GalileoProtocolDecoderTest extends ProtocolTest { var decoder = inject(new GalileoProtocolDecoder(null)); + verifyPosition(decoder, binary( + "01004e01001c0747ea59333030323334303639363034353930000012000063c85e6903000b0321a8f846aba50000000202001e205f5ec863300c4643fdfdbbe6c8fb330000000034e7013505d400000000")); + verifyNotNull(decoder, binary( "01006501001c05cf1f8133303032333430363939303130313000004a000062d8f3ee03000b000f85402088970000000602003503333030323334303639393031303130100000207af3d862300cbe08ee00acfaf001330000760634b301350840090a416b2f42920e")); diff --git a/src/test/java/org/traccar/protocol/Gl200TextProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/Gl200TextProtocolDecoderTest.java index ef82a11..f3a7722 100644 --- a/src/test/java/org/traccar/protocol/Gl200TextProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/Gl200TextProtocolDecoderTest.java @@ -12,6 +12,10 @@ public class Gl200TextProtocolDecoderTest extends ProtocolTest { var decoder = inject(new Gl200TextProtocolDecoder(null)); verifyAttribute(decoder, buffer( + "+RESP:GTERI,271002,863457051562823,,00000002,,10,1,1,0.0,15,28.2,-58.695253,-34.625413,20230119193305,0722,0007,1168,16B3BB,00,0.0,,,,99,210100,2,1,28F8A149F69A3C25,1,0190,20230119193314,07C7$"), + Position.PREFIX_TEMP + 1, 25.0); + + verifyAttribute(decoder, buffer( "+RESP:GTDAR,F10406,865284049582228,,4,0,,,1,18.5,0,129.4,114.015430,22.537279,20210922004634,0460,0000,27BD,0DFC,,,,20210922004635,082B$"), "warningType", 4); diff --git a/src/test/java/org/traccar/protocol/WatchProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/WatchProtocolDecoderTest.java index 7eb167a..37fab7e 100644 --- a/src/test/java/org/traccar/protocol/WatchProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/WatchProtocolDecoderTest.java @@ -17,6 +17,20 @@ public class WatchProtocolDecoderTest extends ProtocolTest { var decoder = inject(new WatchProtocolDecoder(null)); + verifyPosition(decoder, buffer( + "[SG*9059011020*0067*AL,240123,181628,V,54.427538,N,6.409275,W,0.00,0,0,0,19,90,0,0,00000000,1,1,234,10,55C0,3B882A2,132,,10]")); + + verifyPosition(decoder, buffer( + "[SG*9059011020*006b*UD2,240123,162011,A,54.427621,N,6.409190,W,0.00,0,0,8,19,88,0,0,00000000,1,1,FFFF,FFFF,FFFE,3B882A2,132,,00]")); + + verifyAttribute(decoder, buffer( + "[ZJ*5678901234*0001*0009*TEMP,36.5]"), + Position.PREFIX_TEMP + 1, 36.5); + + verifyAttribute(decoder, buffer( + "[ZJ*689466020014198*0003*0113*AL,221121,085515,V,00.000000,N,000.000000,E,0,0,0,0,0,44,0,0,00100000,1,255,460,0,16399,234887445,0,6,WIFI00,68:77:24:1b:e7:a7,-59,WIFI01,68:77:24:1b:e3:30,-75,WIFI02,68:77:24:1b:e3:27,-75,WIFI03,00:41:d2:c0:f2:f1,-76,WIFI04,00:41:d2:c0:f2:f0,-77,WIFI05,68:77:24:1b:e3:d8,-82]"), + Position.KEY_ALARM, Position.ALARM_REMOVING); + verifyNull(decoder, binary( "5b5a4a2a3738393436383035303034323639322a303033342a303433392a4a58544b2c302c77617463685f375f32303232303532363039333935342c312c362c2321414d520a0c0a3c3f96d98367e9468ea245320c0a3c3f96d98367e9468ea245320c0a3c3f96d98367e9468ea245320c389814ffcd762fe49d50ae7a2e0cb528aefbf76911df05c2fbe17d050c2200cff77ef0df4d9b4ab9a4340c449814dbe7c63fa82bc3750d800cc48abbffddb0df8e8fda95e5980c49982ff6cf65f9377d02a39c3aaa0c389805f2ff42c1b80e0a0eb1dc0c2998e9defe15cfa3bdbe80d3540c7298c2f6d9239e3eae3c4a81660c490034dbfd513fedad0c2fc3900cc40039b7f71bb0657ba75558c40cd7813b97ff7219777ec7f401260c7d040003bff6f75fdb898a6ba1140cecd127f7f83357cb73a68a5f680cb081d4f6e749e6af8ed367bc480cec1815dfffd2dbed358112af320ccc21179fffbd17a3a61c133b380c920047defc72a784770ec0fe400c383c42f6faebe76fa736e9d1be0c4918e7decddc67ec9afd87ff220cc418e6bffe6cf6c9ac1f83c3900ca6cad1ffe3da24e1be3b547d03c00c6b00b8fee77f60a76d3e7d0292e20c2918b7bfff76387b793d3a36300c7d0400b7fff7f63ae513ac6f74de0c980016fbff7d01f9b30fca67c7220caa982ff6dbd7bf3d8dfed143ec0c44982fdfcb7b517e26f6ea52420c0ed19cfedb438f179d3fc50ec40c008ad2ffff635fe28dc1ec1f860c76cb7d05bffda53eaebe4d201ae20ccccaffbbfd3db4abb6ddf39d0e0c6b00acfeff406fe4a12661caf80c76982fbffffeb17b2f65472f300c7d04c24bf6ef1b10e47f73fc10b40c76036cfecd4e7837145a6a8e900ccccaf2beeba36fbaa36feb60640c7d0400dfffff73bfa3b87d0256a1700c7d04e4efd6efc23b651eb73e77780ccc1813ffffb39f6baa6f3195080c00007afffee0b9df6346ca08d00c6bca7d04feff4d64a7b56f9855da0c769819fbfd954ea5bd7d040ba6420c4c4c09bfffd5f6c57d01930e7d01220cc48a22dffe30bfcbaf08a795140c7d040433b7ff3cba5f3e336a40060cecbd2bfaf775bea7bde7e095ee0cc4caaef7fb623feeaab69eabc20c8c0021bffd1ea4a1b090175a920c7d046445fbdfc1abe910b0ca56160c7d0440cbd7ef03893c7f7d02e1a8c20c85e42dff5fdaa145759d326b5a0ccc4084f75f8eeb7b15e4eb4ff80c6bc22ef7d7eaf8df3b8ff678cc0cca4026f3cf7518fd731ceca3560cec041ffbe7655eaf822f04c4fe0c7d0478e3fbfcb5dfc8a81fdbb9e20cc418e6d7ff777f26affe37cc020cd7977cbff7d0aecb9727be6a0c0c00bde1f2d797fc8754ed09d4ae0cc498279f7e729fcb9eff70c1a60c7d0478e5bfffc67eef953fda69aa0c7200f1bbf7e891ef5a287cb5b80c983629fee5555f739f8a29279a0c76d103bef73f55a6bf89ba8ce40cc46424f6ded9a194167a067d05880cc4780efeffc37fae944d89bfb40c4464bffffb6dd54e8344394a5c0c49781ffffc653feaa31af59ac00cc464cebfd76ae4e8a55d5b5a4a2a3738393436383035303034323639322a303033352a303434332a4a58544b2c302c77617463685f375f32303232303532363039333935342c322c362c5f24fbbc0c7d04983effcfe35fbd8fff7ce6f60c448a1dfbd715bec3b42448e58a0c0e0421bf5f17ebc31a43301bc40c768ababf4f66cf629ee31fe9900c6b6426bf5f4eb7669dacc439140c945733bff9351e7d04ab6be54ef60ccc98bfbffbf67f63b78d8f42880c7d0400c6f7fffab5cbae8e8275da0c0097ffdefff5dfafb0c4727d04980ccc78d1f6ff1a6b7e37631059fa0c760045f3fd853fea877d03aa87440cc40022f7ffa8b5c58f6e80c58e0ccc4c1f9ffff32fa7af87de04560cb09801f6fdd32efcbdad9495b60c6b987d05bff72d61eb687d05a9f9e20cca57c7ffff6cb1fe3387ea596e0c629823dedfbfc50b97965e44ea0c4918ccbfd7cc75e59fff92e9ee0c8c78e7faff707ffda60ec3ada60c30c217befffcb8f3290f06d75e0c0e8a7bb7dff3eec7b7928ef6680c38ca1cdeff272ba012597d051a520c0018dfffeff27d01e369b3bcd7d80c98146eb2fc7f45c38e1ce53e120c3d5700ff7fd44bee28aa089d900c007157bffffe30302d7d0583585c0ccc5747bfe7f73cff7d02de1098240c7d047865f6feca71d70bdfaab6a20cecb946bfd966be74b61a06c6660c441612ffe7eb966a8c2886cf760ccc7827bffd653ff7980a62e9320c00ca98f7fc1b311a3986700cc20c490017bfff70cfe7bb455637320c6228afbf7e6da4c59763b693740cccc2b5fee1951975760e4a9dca0c0000faffdb255f6f86af4be6fc0cccc2ffdfff7d0225efbc847c42760cb48a8fdffbe23ff1a78782cbe60c7d04980cffff6e6dfc75a6c65a500ce62808bfff24f853748a9537400cb4004ebfeb6e70aa4314903e8c0cb46408ff72d62f44945f64897d040cccca7abfff2db5c6bfcc345e700c7d04c24dd6fd5f95638f78974a800cc4caffffffb17d01c36bdd7d047c2e0c7d0436d1f7f8917f83af7fc5c2180c070449f6fe570f128577c8c97d040c7d047813f6df3fd17d026b6790d1b80cc400c9d6d92dc56497843ed10a0c44986effffe13fef8eef7c717a0c7d049872bbfdad3abe2be0d60b240c4900adbf7d02dfa4ef960fdf23580c629845fefc5a650fbf8b0d4cda0c7d040076b7ef273fe78fce983ae40c4a00ded7ff629f7fab4531501c0c6200b7ffedf13fe6a68f01fb6c0cc49809f77fdb91517fb39e8ba00c760009bf7fd6afe7b46921f27a0cecbd1df6faf99120776e807d03fe0c98ca23fbff3749fb5ed3909c160cc44cbbbfffbd70e77d0367bc2e740c499816f77fe2ffe08edd7d048c9e0c940021beff1df0f1338c2f1a3a0c7d040083feebba1c756e5760c2200c94981dfffdf921b92b99909ba40c7d04984ebbdf7ff0c77d025a1fbfc00c7657b3ff77f4befcae2bf625640c62ca53f7fdb35f2e92af3bd5c60c7d049878bbdfc0dfc1bdaa1918000cc404bbbfefb41ee6b50a39bf180c767874f7fb8ee156320ee600020c69981cffffe0fff6bb2764acaa0cec781bfbff7d0324eb9b4b4d5d5b5a4a2a3738393436383035303034323639322a303033362a303433302a4a58544b2c302c77617463685f375f32303232303532363039333935342c332c362c73580c07ca4fbbfff5bec5abcfac465c0c0042a8beff316aed38fe4603dc0c7d04577d04fefdc929f7294ce7520c0c76984dfaff402fe68ebe113b000c7d0436a6fed465ff4f8d8e3306300c44e434f7f79e84abb8fa081be80c983636bef7e128bf7d03d34c71c80cd7982dffd54cac94536beab1320c058bd6bfff701fe69d1a39d1e80c76caedb77ffea0e47febb469440c0098b2bef5e55eed981672b1c40cd800d1bef4bda58daf7d01d309180c08cadffbfc31799f5613fab2da0c7d049828beffa5eea0bd09a14c2e0c0000e59feb5f9dff7f4945e98e0cc40046ffcfe57fb58f7d053dd9e20c7d040047d7ffd38f67aa9db8d38c0c7698d2df5fe2efc6bb0f5a18220c980367bbfd95dae73e3bf2b59a0c49813796fdf5efab9d3ed7d3d80c9800ebd7fdb831ae8f91811e920c7d04ca74bbff5cdcf45605c25f140c013e029fbfe7ffc299376b409a0c7510009e7d02010f68824cccead60cb13b00f7d5821e6c8d594a06880c75ec00f6e782e8f06b0c610d1a0cc09843dfef117fa5b3aef236f40cdcc208ffff4831f83703ca20c00cc09800bf7fd71eec9ba34e3c200c650f6bffd5bc4dbe7ec5b0f1d80c0d1c1f92ef917fa0b96023eac00c8efb1db6bfa42eed9f69051d4e0c8eff23b2fe4486d56ef44f702e0c8ebc1b9657d46eeea852ac337e0c8efb1f96d9877fc9b34c38f1540c121c2796df13577c727f8cedec0ca9107d05afdd6a9d957ab76c02560c121c2dd6bfd33fa5b844f27d02340cb11037b6e3962e6eaf52d6e7460c2b1c3db2dfe61eef9aad3dcc0a0c542e42d763e709fe723a83ae7c0c7cfa56bf7fedb8763c3f8ab2c00ca40022efff2411604d22a485e00c228adcbfdfcd748293c66b0bf20cb10f0097ff806dcf7a0a640d6e0c5a0400b7e3030ef4ae0a6046f80cb82812fe7b04d77e4bab11894a0c541c24b2dd53fea5891e3824420ca9fb26b2d7156fa485049cac420ca91c2d9edb2487526c2e2260fa0ca9bc25b65ff28e41a34232c0f00c8efb25b649e51ec39c0ae6703a0c70f425a6c820dfaf2f8124c8960c80f42794b323aed9ca9b6924be0cb93b278e3e8d929c36bb70b6360c587b27524f85857d056d214841660cda2f278b4c876eb3186e5acc540ce6832f6e3f0d82f81226e6dc3a0c0b922feff50a03d03c98ae28360c03d62befb54ab611de0c8addee0c84d626b7fdb4461556dc0153040c0b0f27ff5781c5c2b32f6762140c49bf2dfaf521969b702ecb11d80c7d050f27cfed75bfab95dc4af3180c011c3d8e7451df80a5cd0948080c7c2e35f2c7b0becca22e50769e0c7c1c3d965e628f46a9a58ae6100c7c2e3b965f4a6b5ebd1436b0b00c7c863eaedf18c7816cdeeed7e20c2b3e3df6b73952b2b1abc048a00c7cfb3db6cd67ae68cda18af9d60c2bff3e96df12ff61b39627cd580c7c863fd6cd810ee595d85ee6645d5b5a4a2a3738393436383035303034323639322a303033372a303433372a4a58544b2c302c77617463685f375f32303232303532363039333935342c342c362c0c7cff3fb65f812fe196dc62d8360c7c2e3db2de738fae9ca7c7236c0c2b2e3d96df6c1d775a3df5a47e0c7c3e3f96fe943dc07e81e170700c75503fb7d6a6197f1b08df85440c5a133ab6d6a0e68f3acb04b7b00cfa293fd6cfc20c390d5265d3c80c581347b278077d03dc22d9e49c680ce64d47924e8dcdffe9be19dc100cb90f4f9e612d2201961c2e111c0c003b4febb58a96c809ab5a71040ce6d759fbddba54b2aa9d9d983e0cc029576ecf1f703099d84994520c4029579e7d0281577073f5629dd80c5a2952b6fed177177d01e57d0175c20cd8647d044f7e3c58aba523ddb0720cb56753d3e9c6799f95938401f60c756414ff5f00fb57bc4d7e111c0c7c085573ef743ee19ca30057e00c752e5ab77e34eec69f3cbe53940c542e4d96d6e7ff03854a9506620c7cff55b6efca197610a86606180c7cfb55b67eb25f4b999c002bf20c7c107d03beeb451fad8d042492740cb8f05eb5ff664f679c1cc991c60ce1671bffd33d9445b57d0584c7d60c07781dfef5e3ee81b45ff8a8c80cc40072b7dfe6fe6e978257253a0cb1131fe6783035868e439b00d80c583b27b17ecb53dd165c3422180c703b2fbeb18d023e14d90304700c3cce2b93cdc2e6b3550a5546160cb13b3b72fe24273859059b52040c224d34edc742f6bb7c877d02b5940cb84d37cdcfcbc3f03a041cf4ac0ca4923a9f3b74e805b235cce8660c759000fbfd90565072aa7d03bb520cb592017f411dcbe80a0cc420360c09d6528fcf2e25b382ee46d75a0ce2e853d3cfb617fd7d023f05e0780c07cc3bbabfa9f6cec5aa48ac600c404208fb678a4cf16a9c09098c0cf14244fbdfc2afe7932fe57d02900c011c369e7d0264a8570a54f9a2e80cb1103daed6249fe59dc888c2ac0cb1103573c5f697be759923ecc80c705f7d059effaaa4b09b976f375a0c804223bbed89767d041693edab180cb49819d7eb5a8573bb10c951540c3c643af74f021f25b6dd3b7d02040c07982bd73fb31fe38f09a227a40c037610ff7d03c6058098fef936a80c03b808debbe055a1a71319128c0c6b8f2e9e3bb52d71c226d3141a0cdab82d7fa9d416167a1cb950020c03c32bb23ee9e3743f3b6853060cc02937adb5157d05f4a6960c1b680c4076365e6b754bda9394a7aa720c06293ef23313fb1b94bcc2c09a0ce676006bbd8e0417941b90d23c0cb9294f7d01fd3d65748cf6d1cc220c03767d035e3a65e6f2514ab1db060ce6d965bf4035f65c79a9e4446a0ce62921dbf46457b56cd65f6c500c584d6bba7ea8166edd6cf7693a0cb939227bfca25f82a7c4202f2e0c06ce2b9a4f0d95f39eb43c22840c06901eef6fd15fe48f452000e00c62023afbffb269beba0ee0ac540ce6ec00f37b8139f2026e80f1440c22501dfe7d017d03ed8c3ff6803f240cc48ae3b7fd725e63a347cd64100c0094f8efdeb0a9f35c83eb06b00c005d5b5a4a2a3738393436383035303034323639322a303033382a303433332a4a58544b2c302c77617463685f375f32303232303532363039333935342c352c362c6647deef2df57fb68fd76b660c44e43cbfefc0beec867d025c3f920cb4507d01ff6f42ee6c1f58a0db0e0c7d045701ff7f19f9f90fdff037c20c4404259efcd47d02a52b7ef6df0e0c7d04d128f3578db14779993109560ce1e41ecffd2851af49256b1ecc0c7d049837ffff707168db3dd1ac240cc09419f7f39a7d013d6ec1b4e55c0cc4881cff5f49f55fadc52285a40c06ce9ad7dbb8349b97031ac3b00c407d049d9bed74dfadad950eab560c06799ffac7a924b18bdf11c3d40c8054a2f777522e65be921a77240c8042a19bff706fe5b7e3e7d0360cd82840bff3f4fe429bea0081560c0064419fd9157f8b9c797e92c20cc47fe2b7d5e6ee45bf0524010e0c0894299e7d037e4553bcbbc0989e0c40501bbbdc926f8daf53885e0a0c80971ffee559f5bf98ed54cf140c00581abbffac75b88b14d5e3780c5a046dd66fd7bfe5b7ca749df40c403672bbcfe47ee797860ded5e0cb5502efb7ee2ffc7bbdc27d0880c44ca08fbf7031ecd9321d21ef40cdc9806fefde36f0699ad1569420c22cb1bfbdc974fcb900ab601440c00cb1cfbdfd2f7d2730b0b46680c0b4203dfef309fe0adc121e2080c225829feeb901f25b926343bae0c624204dfff4875b69ceda4df4c0c499886ffe7301e8e8bf9ef0a260cdce408dbef829fe45337e98d860c010800ef76088d8015f3b2c84e0c755c3ecfc898f50fbcdb9344220c7c7d03459349337d01e4949da1b4ec0c7cf046ae6e4a90df3552070a5e0c7cf045d23fbba0951147986eca0c7536426e6ef2ef0b7d01c22fd2960cb8284e9db92d40552988334f200cb8024acdbfea90d13b545fe35e0cb8f04d5e48659d48b97c1096140c7c084f79df4402702126bf358a0cb8a74d4def66535e145638d12e0c543e4d8edfa2531b15a340eb800cb83e4eafbd9031291a8563e4780c54a74ef1c7300da79aa94bb67d050cb8f04eba6fb0325813871511b80ce20ff6fffd404ed58ecf264c8e0c7c0f1cb3fe1a36fb7187c379d00c7c3e52f6727d0261ca8bdd1361b80cb8d64d9a4fb1cfe0aadaaa7d05c40c2b2e44b2bfb9b4dcad9d7d0200280c7c3b47d5db803fc2aee71a77f00c7c1343b2bfa06ee6ad3228f10a0c7c3b4a76477fe7650b0c809ca80c54d74b92dbc327134514d6126e0c7c5f4a8f4f74efaaa5cd0a43bc0c7c104bb64ff5ce604fa2028b680c7cff4aaec7f7a9394cc4c599e60cb8ce52eeb553d215a6a466b4120c750f4fae5f9816c04a0a3f751e0c75e04f73c58e96bb4b925a4c680cb80f4b6e3fe1635614bbdeccbc0c7c3b4faf7e825e42d473ee76800ce298578ffcb61f0af936387bbe0cb800e39bf62410681583e0d2b20cb4987d05ff7f297bf69eaf4cd8b40cb57815bf7f300fcffe9fae966a0cb497acd75fd37f648d00d141a00cc48af9fffe1a3b979b8f8573e80c29bff1bf4b94c6fd7c3eec075e0c7cce1f5d5b5a4a2a3738393436383035303034323639322a303033392a303065352a4a58544b2c302c77617463685f375f32303232303532363039333935342c362c362c8f5cf9f34fa6edceb18c0ca4ce436e7d02d329de94b63eb11a0cb894438f44cf753dbc1a83b4560cb8e44391eff729d4155a231bf40cb59443f373b4288492cd6e38160c5a42049bfec8678ad42bce0c560cb12e39fec3d1fe24b5572ee0be0cb1ce35fe33688455aa74e3ffa40cb1d635df4b704160ae864a7d03440cb10f3267dbf4a21d540ca1051c0cb11337724f8747f5547d054e91660cb1a73692df964f3bbb0758d41a0cfe05b60c314460297eae4185f20cad673ceb6dfa05ddbe0278d5de5d"));
https://github.com/traccar/traccar.gitdiff --git a/src/main/java/org/traccar/api/resource/CommandResource.java b/src/main/java/org/traccar/api/resource/CommandResource.java
gitbug-java_data_traccar-traccar.json_8
diff --git a/src/main/java/org/traccar/protocol/TramigoFrameDecoder.java b/src/main/java/org/traccar/protocol/TramigoFrameDecoder.java index e4c94dc..4b0fe52 100644 --- a/src/main/java/org/traccar/protocol/TramigoFrameDecoder.java +++ b/src/main/java/org/traccar/protocol/TramigoFrameDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 - 2019 Anton Tananaev ([email protected]) + * Copyright 2015 - 2023 Anton Tananaev ([email protected]) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,7 +33,7 @@ public class TramigoFrameDecoder extends BaseFrameDecoder { if (buf.getUnsignedByte(buf.readerIndex()) == 0x80) { length = buf.getUnsignedShortLE(buf.readerIndex() + 6); } else { - length = buf.getUnsignedShort(buf.readerIndex() + 6); + length = buf.getUnsignedShortLE(buf.readerIndex() + 1); } if (length <= buf.readableBytes()) { diff --git a/src/test/java/org/traccar/protocol/TramigoFrameDecoderTest.java b/src/test/java/org/traccar/protocol/TramigoFrameDecoderTest.java index a093d94..cf997c2 100644 --- a/src/test/java/org/traccar/protocol/TramigoFrameDecoderTest.java +++ b/src/test/java/org/traccar/protocol/TramigoFrameDecoderTest.java @@ -11,6 +11,10 @@ public class TramigoFrameDecoderTest extends ProtocolTest { var decoder = inject(new TramigoFrameDecoder()); verifyFrame( + binary("0480001df35b1b69101a023ef34f0090436d38003200380e0000850081c0e4ff6d542f00000015000000050000000000007600a20100008f436d3800014400000000000000000021000a0006005a574a6169726f7320486972692043656e747265205072696d617279205363686f6f6c536f7574686572746f6e486172617265"), + decoder.decode(null, null, binary("0480001df35b1b69101a023ef34f0090436d38003200380e0000850081c0e4ff6d542f00000015000000050000000000007600a20100008f436d3800014400000000000000000021000a0006005a574a6169726f7320486972692043656e747265205072696d617279205363686f6f6c536f7574686572746f6e486172617265"))); + + verifyFrame( binary("8000ed2bb0009c000101bee000050b09633d925b5472616d69676f3a205472697020737461727465642c2053686f636b2053656e736f722c206174204b696e6720437265656b20526f61642d46726565746f776e205374726565742c20506f727420486172636f7572742c205269766572732c204e472c20342e37363336312c20372e30313836382c2030373a31383a333620536570203320454f46"), decoder.decode(null, null, binary("8000ed2bb0009c000101bee000050b09633d925b5472616d69676f3a205472697020737461727465642c2053686f636b2053656e736f722c206174204b696e6720437265656b20526f61642d46726565746f776e205374726565742c20506f727420486172636f7572742c205269766572732c204e472c20342e37363336312c20372e30313836382c2030373a31383a333620536570203320454f46")));
https://github.com/traccar/traccar.gitdiff --git a/src/main/java/org/traccar/protocol/TramigoFrameDecoder.java b/src/main/java/org/traccar/protocol/TramigoFrameDecoder.java
gitbug-java_data_traccar-traccar.json_9
diff --git a/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java index 343141d..a7accf0 100644 --- a/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2022 Anton Tananaev ([email protected]) + * Copyright 2012 - 2023 Anton Tananaev ([email protected]) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -510,6 +510,9 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { case 0x0D: position.set("runtime", buf.readUnsignedIntLE()); break; + case 0x25: + position.set(Position.KEY_DRIVER_UNIQUE_ID, String.valueOf(buf.readUnsignedIntLE())); + break; case 0xA0: position.set(Position.KEY_FUEL_USED, buf.readUnsignedIntLE() * 0.001); break; @@ -624,6 +627,13 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { photo = Unpooled.buffer(); requestPhotoPacket(channel, remoteAddress, imei, "camera_picture.jpg", 0); return null; + case "D82": + Position position = new Position(getProtocolName()); + position.setDeviceId(getDeviceSession(channel, remoteAddress, imei).getDeviceId()); + getLastLocation(position, null); + String result = buf.toString(index + 1, buf.writerIndex() - index - 4, StandardCharsets.US_ASCII); + position.set(Position.KEY_RESULT, result); + return position; case "CCC": return decodeBinaryC(channel, remoteAddress, buf); case "CCE": diff --git a/src/test/java/org/traccar/protocol/MeitrackProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/MeitrackProtocolDecoderTest.java index ce0a1e9..407d7a9 100644 --- a/src/test/java/org/traccar/protocol/MeitrackProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/MeitrackProtocolDecoderTest.java @@ -11,6 +11,13 @@ public class MeitrackProtocolDecoderTest extends ProtocolTest { var decoder = inject(new MeitrackProtocolDecoder(null)); + verifyAttribute(decoder, buffer( + "$$u28,864606044993987,D82,0*D6"), + Position.KEY_RESULT, "D82,0"); + + verifyPositions(decoder, binary( + "24245B3139312C3836343630363034343939333938372C4343452C010000000200500013000601250500060007111B00470206080000093E000AE7030B0000199E011A850306028D7A570103F35ACC0604F9D06C2B0CB92E00000D3FA40C00250CA2B900010E0CCC010000B6276313000000004B00120006012A0500060007111B00470206080000093E000AE7030B0000199E011A7C0305028D7A570103F35ACC0604F9D06C2B0CB92E00000D3FA40C00010E0CCC010000B6276313000000002A31340D0A")); + verifyPositions(decoder, binary( "24246a3138312c3836343238313034313930383330332c4343452c00000000010093001f000505000600070714001502090800000900000a00000b0000160a001706001904001ad90440230006023279570103305ccc0604f536492b0c510300000d495701001c014000000b0e0ccc010000922781abb90c00002a030034212b03008b082c030053082d03009e082e030034212f030034213003003421310300342149090400000000000000004b07010104574946492a36310d0a"));
https://github.com/traccar/traccar.gitdiff --git a/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java
gitbug-java_data_traccar-traccar.json_10
diff --git a/src/main/java/org/traccar/protocol/TramigoProtocolDecoder.java b/src/main/java/org/traccar/protocol/TramigoProtocolDecoder.java index 1296929..ddd669b 100644 --- a/src/main/java/org/traccar/protocol/TramigoProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/TramigoProtocolDecoder.java @@ -153,8 +153,8 @@ public class TramigoProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_STATUS, status); position.setValid(true); - position.setLatitude(buf.readInt() * 0.00001); - position.setLongitude(buf.readInt() * 0.00001); + position.setLatitude(buf.readIntLE() * 0.00001); + position.setLongitude(buf.readIntLE() * 0.00001); position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShortLE())); position.setCourse(buf.readUnsignedShortLE()); @@ -172,7 +172,7 @@ public class TramigoProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedByte(); // reserved break; case 1: - buf.skipBytes(buf.readUnsignedShortLE()); // landmark + buf.skipBytes(buf.readUnsignedShortLE() - 3); // landmark break; case 4: buf.skipBytes(53); // trip @@ -191,7 +191,7 @@ public class TramigoProtocolDecoder extends BaseProtocolDecoder { buf.skipBytes(40); // analog break; case 50: - buf.skipBytes(buf.readUnsignedShortLE()); // console + buf.skipBytes(buf.readUnsignedShortLE() - 3); // console break; case 255: buf.skipBytes(4); // acknowledgement diff --git a/src/test/java/org/traccar/protocol/TramigoProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/TramigoProtocolDecoderTest.java index fdef8ce..d692a41 100644 --- a/src/test/java/org/traccar/protocol/TramigoProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/TramigoProtocolDecoderTest.java @@ -10,8 +10,8 @@ public class TramigoProtocolDecoderTest extends ProtocolTest { var decoder = inject(new TramigoProtocolDecoder(null)); - /*verifyNull(decoder, binary( - "0480001df35b1b69101a023ef34f0090436d38003200380e0000850081c0e4ff6d542f00000015000000050000000000007600a20100008f436d3800014400000000000000000021000a0006005a574a6169726f7320486972692043656e747265205072696d617279205363686f6f6c536f7574686572746f6e486172617265"));*/ + verifyPosition(decoder, binary( + "0480001df35b1b69101a023ef34f0090436d38003200380e0000850081c0e4ff6d542f00000015000000050000000000007600a20100008f436d3800014400000000000000000021000a0006005a574a6169726f7320486972692043656e747265205072696d617279205363686f6f6c536f7574686572746f6e486172617265")); verifyAttributes(decoder, binary( "8000c426b000a6000101c557037598050d5c8a595472616d69676f3a204d6f76696e672c20302e3132206b6d2045206f66204c617275742054696e2049736c616d6963205072696d617279205363686f6f6c2c2054616970696e672c20506572616b2c204d592c20342e38333134392c203130302e37333038352c204e572077697468207370656564203130206b6d2f682c2030303a34393a30382041756720392020454f46"));
https://github.com/traccar/traccar.gitdiff --git a/src/main/java/org/traccar/protocol/TramigoProtocolDecoder.java b/src/main/java/org/traccar/protocol/TramigoProtocolDecoder.java
gitbug-java_data_traccar-traccar.json_11
diff --git a/src/main/java/org/traccar/protocol/TotemProtocolDecoder.java b/src/main/java/org/traccar/protocol/TotemProtocolDecoder.java index fc3dce8..6f039c3 100644 --- a/src/main/java/org/traccar/protocol/TotemProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/TotemProtocolDecoder.java @@ -176,7 +176,21 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { .any() .compile(); - private static final Pattern PATTERN_OBD = new PatternBuilder() + private static final Pattern PATTERN_E2 = new PatternBuilder() + .text("$$") // header + .number("dddd") // length + .number("xx") // type + .number("(d+)|") // imei + .number("(dd)(dd)(dd)") // date (yymmdd) + .number("(dd)(dd)(dd),") // time (hhmmss) + .number("(-?d+.d+),") // longitude + .number("(-?d+.d+),") // latitude + .expression("(.+)") // rfid + .number("|xx") // checksum + .any() + .compile(); + + private static final Pattern PATTERN_E5 = new PatternBuilder() .text("$$") // header .number("dddd") // length .number("xx") // type @@ -396,6 +410,15 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { int type = Integer.parseInt(sentence.substring(6, 8), 16); + switch (type) { + case 0xE2: + return decodeE2(channel, remoteAddress, sentence); + case 0xE5: + return decodeE5(channel, remoteAddress, sentence); + default: + break; + } + Parser parser = new Parser(PATTERN4, sentence); if (!parser.matches()) { return null; @@ -473,9 +496,34 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { return position; } - private Position decodeObd(Channel channel, SocketAddress remoteAddress, String sentence) { + private Position decodeE2(Channel channel, SocketAddress remoteAddress, String sentence) { + + Parser parser = new Parser(PATTERN_E2, sentence); + if (!parser.matches()) { + return null; + } + + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); + if (deviceSession == null) { + return null; + } + + Position position = new Position(getProtocolName()); + position.setDeviceId(deviceSession.getDeviceId()); + + position.setValid(true); + position.setTime(parser.nextDateTime()); + position.setLongitude(parser.nextDouble()); + position.setLatitude(parser.nextDouble()); + + position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next()); + + return position; + } + + private Position decodeE5(Channel channel, SocketAddress remoteAddress, String sentence) { - Parser parser = new Parser(PATTERN_OBD, sentence); + Parser parser = new Parser(PATTERN_E5, sentence); if (!parser.matches()) { return null; } @@ -517,9 +565,7 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder { String sentence = (String) msg; Position position; - if (sentence.contains("$Cloud")) { - position = decodeObd(channel, remoteAddress, sentence); - } else if (sentence.charAt(2) == '0') { + if (sentence.charAt(2) == '0') { position = decode4(channel, remoteAddress, sentence); } else if (sentence.contains("$GPRMC")) { position = decode12(channel, remoteAddress, sentence, PATTERN1); diff --git a/src/test/java/org/traccar/protocol/TotemProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/TotemProtocolDecoderTest.java index df57345..1e432bd 100644 --- a/src/test/java/org/traccar/protocol/TotemProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/TotemProtocolDecoderTest.java @@ -2,6 +2,7 @@ package org.traccar.protocol; import org.junit.Test; import org.traccar.ProtocolTest; +import org.traccar.model.Position; public class TotemProtocolDecoderTest extends ProtocolTest { @@ -10,6 +11,10 @@ public class TotemProtocolDecoderTest extends ProtocolTest { var decoder = inject(new TotemProtocolDecoder(null)); + verifyAttribute(decoder, text( + "$$0494E2123456789012345|150425223945,113.925525,22.55814,1122334455|38"), + Position.KEY_DRIVER_UNIQUE_ID, "1122334455"); + verifyPosition(decoder, text( "$$0111AA353081090067318|0804400022070722520240400005B364ED5003107300001.700000002245.3919N10231.6952W000001860E"));
https://github.com/traccar/traccar.gitdiff --git a/src/main/java/org/traccar/protocol/TotemProtocolDecoder.java b/src/main/java/org/traccar/protocol/TotemProtocolDecoder.java
gitbug-java_data_traccar-traccar.json_12
diff --git a/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java index a7accf0..5c5ba4b 100644 --- a/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java @@ -420,6 +420,12 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { case 0x15: position.set(Position.KEY_INPUT, buf.readUnsignedByte()); break; + case 0x47: + int lockState = buf.readUnsignedByte(); + if (lockState > 0) { + position.set(Position.KEY_LOCK, lockState == 2); + } + break; case 0x97: position.set(Position.KEY_THROTTLE, buf.readUnsignedByte()); break; diff --git a/src/test/java/org/traccar/protocol/MeitrackProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/MeitrackProtocolDecoderTest.java index 407d7a9..419eddf 100644 --- a/src/test/java/org/traccar/protocol/MeitrackProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/MeitrackProtocolDecoderTest.java @@ -11,6 +11,10 @@ public class MeitrackProtocolDecoderTest extends ProtocolTest { var decoder = inject(new MeitrackProtocolDecoder(null)); + verifyAttribute(decoder, binary( + "24245b3131342c3836343630363034343939333938372c4343452c0000000001005000130006012305000600070f1b004702060800000900000a00000b0000199d011a00000602d179570103b25ccc0604cf04862b0cc65b01000da4090d001c01000000010e0ccc010000b627be11000000002a41300d0a"), + Position.KEY_LOCK, true); + verifyAttribute(decoder, buffer( "$$u28,864606044993987,D82,0*D6"), Position.KEY_RESULT, "D82,0");
https://github.com/traccar/traccar.gitdiff --git a/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java
gitbug-java_data_traccar-traccar.json_13
diff --git a/src/main/java/org/traccar/helper/Parser.java b/src/main/java/org/traccar/helper/Parser.java index aa39e1a..c2aea28 100644 --- a/src/main/java/org/traccar/helper/Parser.java +++ b/src/main/java/org/traccar/helper/Parser.java @@ -50,6 +50,17 @@ public class Parser { public boolean hasNext(int number) { for (int i = position; i < position + number; i++) { String value = matcher.group(i); + if (value == null || value.isEmpty()) { + position += number; + return false; + } + } + return true; + } + + public boolean hasNextAny(int number) { + for (int i = position; i < position + number; i++) { + String value = matcher.group(i); if (value != null && !value.isEmpty()) { return true; } diff --git a/src/main/java/org/traccar/protocol/Gl200TextProtocolDecoder.java b/src/main/java/org/traccar/protocol/Gl200TextProtocolDecoder.java index 517499f..28308ab 100644 --- a/src/main/java/org/traccar/protocol/Gl200TextProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Gl200TextProtocolDecoder.java @@ -956,7 +956,7 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_POWER, power * 0.001); } - if (parser.hasNext(12)) { + if (parser.hasNextAny(12)) { position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000); position.set(Position.KEY_HOURS, parseHours(parser.next())); diff --git a/src/main/java/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Gps103ProtocolDecoder.java index 28efa3c..d1c35b4 100644 --- a/src/main/java/org/traccar/protocol/Gps103ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Gps103ProtocolDecoder.java @@ -225,7 +225,7 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { getConfig(), parser.nextHexInt(0), parser.nextHexInt(0)))); } - if (parser.hasNext(20)) { + if (parser.hasNextAny(20)) { String utcHours = parser.next(); String utcMinutes = parser.next(); diff --git a/src/main/java/org/traccar/protocol/StartekProtocolDecoder.java b/src/main/java/org/traccar/protocol/StartekProtocolDecoder.java index 8e3624c..d75da7f 100644 --- a/src/main/java/org/traccar/protocol/StartekProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/StartekProtocolDecoder.java @@ -221,7 +221,7 @@ public class StartekProtocolDecoder extends BaseProtocolDecoder { } } - if (parser.hasNext(6)) { + if (parser.hasNextAny(6)) { position.set(Position.KEY_RPM, parser.nextInt()); position.set(Position.KEY_ENGINE_LOAD, parser.nextInt()); position.set("airFlow", parser.nextInt()); diff --git a/src/main/java/org/traccar/protocol/WialonProtocolDecoder.java b/src/main/java/org/traccar/protocol/WialonProtocolDecoder.java index 3d57525..b87ba2b 100644 --- a/src/main/java/org/traccar/protocol/WialonProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/WialonProtocolDecoder.java @@ -101,7 +101,7 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder { position.setTime(new Date()); } - if (parser.hasNext(9)) { + if (parser.hasNextAny(9)) { position.setLatitude(parser.nextCoordinate()); position.setLongitude(parser.nextCoordinate()); position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0))); diff --git a/src/test/java/org/traccar/protocol/Gl200TextProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/Gl200TextProtocolDecoderTest.java index f3a7722..5696353 100644 --- a/src/test/java/org/traccar/protocol/Gl200TextProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/Gl200TextProtocolDecoderTest.java @@ -11,6 +11,9 @@ public class Gl200TextProtocolDecoderTest extends ProtocolTest { var decoder = inject(new Gl200TextProtocolDecoder(null)); + verifyPositions(decoder, false, buffer( + "+BUFF:GTFRI,2E0503,861106050005423,,,0,1,,,,,,,,,,,,0,0,,98,1,0,,,20200101000001,0083$")); + verifyAttribute(decoder, buffer( "+RESP:GTERI,271002,863457051562823,,00000002,,10,1,1,0.0,15,28.2,-58.695253,-34.625413,20230119193305,0722,0007,1168,16B3BB,00,0.0,,,,99,210100,2,1,28F8A149F69A3C25,1,0190,20230119193314,07C7$"), Position.PREFIX_TEMP + 1, 25.0);
https://github.com/traccar/traccar.gitdiff --git a/src/main/java/org/traccar/helper/Parser.java b/src/main/java/org/traccar/helper/Parser.java
gitbug-java_data_traccar-traccar.json_14
diff --git a/src/main/java/org/traccar/protocol/Jt600FrameDecoder.java b/src/main/java/org/traccar/protocol/Jt600FrameDecoder.java index bfefb94..f7890f8 100644 --- a/src/main/java/org/traccar/protocol/Jt600FrameDecoder.java +++ b/src/main/java/org/traccar/protocol/Jt600FrameDecoder.java @@ -35,7 +35,7 @@ public class Jt600FrameDecoder extends BaseFrameDecoder { char type = (char) buf.getByte(buf.readerIndex()); if (type == '$') { - boolean longFormat = Jt600ProtocolDecoder.isLongFormat(buf, buf.readerIndex() + 1); + boolean longFormat = Jt600ProtocolDecoder.isLongFormat(buf); int length = buf.getUnsignedShort(buf.readerIndex() + (longFormat ? 8 : 7)) + 10; if (length <= buf.readableBytes()) { return buf.readRetainedSlice(length); diff --git a/src/main/java/org/traccar/protocol/Jt600ProtocolDecoder.java b/src/main/java/org/traccar/protocol/Jt600ProtocolDecoder.java index 9ed44f5..dc763de 100644 --- a/src/main/java/org/traccar/protocol/Jt600ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/Jt600ProtocolDecoder.java @@ -86,8 +86,8 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { } - static boolean isLongFormat(ByteBuf buf, int flagIndex) { - return buf.getUnsignedByte(flagIndex) >> 4 >= 7; + static boolean isLongFormat(ByteBuf buf) { + return buf.getUnsignedByte(buf.readerIndex() + 8) == 0; } static void decodeBinaryLocation(ByteBuf buf, Position position) { @@ -123,9 +123,9 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { List<Position> positions = new LinkedList<>(); - buf.readByte(); // header + boolean longFormat = isLongFormat(buf); - boolean longFormat = isLongFormat(buf, buf.readerIndex()); + buf.readByte(); // header String id = String.valueOf(Long.parseLong(ByteBufUtil.hexDump(buf.readSlice(5)))); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id); diff --git a/src/test/java/org/traccar/protocol/Jt600FrameDecoderTest.java b/src/test/java/org/traccar/protocol/Jt600FrameDecoderTest.java index 8e408e5..895a0b0 100644 --- a/src/test/java/org/traccar/protocol/Jt600FrameDecoderTest.java +++ b/src/test/java/org/traccar/protocol/Jt600FrameDecoderTest.java @@ -11,6 +11,14 @@ public class Jt600FrameDecoderTest extends ProtocolTest { var decoder = inject(new Jt600FrameDecoder()); verifyFrame( + binary("2460201102320112003401010000000422434199114158229e000000000009000000000010e06400000000000020100e0868817043592664000000000000"), + decoder.decode(null, null, binary("2460201102320112003401010000000422434199114158229e000000000009000000000010e06400000000000020100e0868817043592664000000000000"))); + + verifyFrame( + binary("24657060730131001b13111710361906538525079524797f000000000000000003f300036c"), + decoder.decode(null, null, binary("24657060730131001b13111710361906538525079524797f000000000000000003f300036c"))); + + verifyFrame( binary("2480413009781914003406102107544354193631006213423b00000000006c070000000020e064f91ea0671d00020f0f0f0f0f0f0f0f0f0f07f100ea0f6e"), decoder.decode(null, null, binary("2480413009781914003406102107544354193631006213423b00000000006c070000000020e064f91ea0671d00020f0f0f0f0f0f0f0f0f0f07f100ea0f6e")));
https://github.com/traccar/traccar.gitdiff --git a/src/main/java/org/traccar/protocol/Jt600FrameDecoder.java b/src/main/java/org/traccar/protocol/Jt600FrameDecoder.java
gitbug-java_data_traccar-traccar.json_15
diff --git a/src/main/java/org/traccar/protocol/T55ProtocolDecoder.java b/src/main/java/org/traccar/protocol/T55ProtocolDecoder.java index 3be161f..4db76f6 100644 --- a/src/main/java/org/traccar/protocol/T55ProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/T55ProtocolDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2022 Anton Tananaev ([email protected]) + * Copyright 2012 - 2023 Anton Tananaev ([email protected]) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -150,6 +150,18 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder { .number("xx") // checksum .compile(); + private static final Pattern PATTERN_GPTXT = new PatternBuilder() + .text("$GPTXT,") + .text("NET,") + .number("(d+),") // device id + .expression("([^,]+),") // network operator + .number("(-d+),") // rssi + .number("(d+) ") // mcc + .number("(d+)") // mnc + .text("*") + .number("xx") // checksum + .compile(); + private Position position = null; private Position decodeGprmc( @@ -328,6 +340,30 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder { return position; } + private Position decodeGptxt(Channel channel, SocketAddress remoteAddress, String sentence) { + + Parser parser = new Parser(PATTERN_GPTXT, sentence); + if (!parser.matches()) { + return null; + } + + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); + if (deviceSession == null) { + return null; + } + + Position position = new Position(getProtocolName()); + + getLastLocation(position, null); + + position.set(Position.KEY_OPERATOR, parser.next()); + position.set(Position.KEY_RSSI, parser.nextInt()); + position.set("mcc", parser.nextInt()); + position.set("mnc", parser.nextInt()); + + return position; + } + private Position decodePubx(Channel channel, SocketAddress remoteAddress, String sentence) { Parser parser = new Parser(PATTERN_PUBX, sentence); @@ -421,6 +457,8 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder { return decodeQze(channel, remoteAddress, sentence); } else if (sentence.startsWith("$PUBX")) { return decodePubx(channel, remoteAddress, sentence); + } else if (sentence.startsWith("$GPTXT")) { + return decodeGptxt(channel, remoteAddress, sentence); } return null; diff --git a/src/test/java/org/traccar/protocol/T55ProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/T55ProtocolDecoderTest.java index 1622f64..e04e473 100644 --- a/src/test/java/org/traccar/protocol/T55ProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/T55ProtocolDecoderTest.java @@ -11,6 +11,9 @@ public class T55ProtocolDecoderTest extends ProtocolTest { var decoder = inject(new T55ProtocolDecoder(null)); + verifyAttributes(decoder, text( + "$GPTXT,NET,1003,A1,-53,232 01*77")); + verifyPosition(decoder, text( "$PUBX,00,130209.00,3650.51159,N,01346.10602,E,785.947,D3,4.1,5.2,0.163,87.43,-0.054,7.0,0.88,1.21,0.88,24,01012,0*6D"));
https://github.com/traccar/traccar.gitdiff --git a/src/main/java/org/traccar/protocol/T55ProtocolDecoder.java b/src/main/java/org/traccar/protocol/T55ProtocolDecoder.java
gitbug-java_data_traccar-traccar.json_16
diff --git a/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java index 3acd87b..3f1f7f5 100644 --- a/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java @@ -554,8 +554,15 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { buf.skipBytes(length - 2); break; case 0xFEA8: - buf.readUnsignedByte(); // battery status - position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte()); + if (buf.readUnsignedByte() > 0) { + position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte()); + } else { + buf.readUnsignedByte(); + } + buf.readUnsignedByte(); // battery 2 status + buf.readUnsignedByte(); // battery 2 level + buf.readUnsignedByte(); // battery 3 status + buf.readUnsignedByte(); // battery 3 level buf.readUnsignedByte(); // battery alert break; default: diff --git a/src/test/java/org/traccar/protocol/MeitrackProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/MeitrackProtocolDecoderTest.java index 8533455..ec45933 100644 --- a/src/test/java/org/traccar/protocol/MeitrackProtocolDecoderTest.java +++ b/src/test/java/org/traccar/protocol/MeitrackProtocolDecoderTest.java @@ -12,7 +12,7 @@ public class MeitrackProtocolDecoderTest extends ProtocolTest { var decoder = inject(new MeitrackProtocolDecoder(null)); verifyAttribute(decoder, binary( - "2424663137302c3836353431333035303839313733372c4343452c00000000010088001800050501060907101400150008080000091c000a18000b1e001606001a0000402300fe9000000602d5fe5ffe038f2a1f0904102c8d2b0cd23f02000df03203001c01000000050e0cf90101003170017ac80892ff4b16010113464444204c5445284c54452042414e44203329fea50601ffffff7ffffea807024d0000000000feb20501010000002a36430d0a"), + "2424593434312c3836353431333035303839313733372c4343452c00000000030088001800050501061607191400150008080000098e000a05000b0c001608001a0000402300fe9000000602c3fe5ffe03e22a1f0904e6688d2b0cd94002000d5f6f03001c01000000050e0cf901010032700298c80899ff4b16010113464444204c5445284c54452042414e44203329fea50601ffffff7ffffea807024d0000000000feb205010000000083001700050501061607191400150008080000098e000a05000b0c001608001a0000405100fe9000000502c3fe5ffe03e22a1f0904e6688d2b0cd94002000d606f0300050e0cf901010032700298c80899ff4b16010113464444204c5445284c54452042414e44203329fea50601ffffff7ffffea807024d0000000000feb205010000000088001800050501061607151400150008080000098e000a05000b0c001607001a0000402300fe9000000602c3fe5ffe03e22a1f0904f0688d2b0cd94002000d696f03001c01000000050e0cf901010032700298c80897ff4b16010113464444204c5445284c54452042414e44203329fea50601ffffff7ffffea807024d0000000000feb20501000000002a36320d0a"), Position.KEY_BATTERY_LEVEL, 77); verifyAttribute(decoder, binary(
https://github.com/traccar/traccar.gitdiff --git a/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/main/java/org/traccar/protocol/MeitrackProtocolDecoder.java