diff --git a/redpen-core/src/main/java/cc/redpen/validator/sentence/SymbolWithSpaceValidator.java b/redpen-core/src/main/java/cc/redpen/validator/sentence/SymbolWithSpaceValidator.java index c47aee576..131e246e3 100644 --- a/redpen-core/src/main/java/cc/redpen/validator/sentence/SymbolWithSpaceValidator.java +++ b/redpen-core/src/main/java/cc/redpen/validator/sentence/SymbolWithSpaceValidator.java @@ -25,6 +25,9 @@ import java.util.Set; +import static java.lang.Character.isLetterOrDigit; +import static java.lang.Character.isWhitespace; + /** * Validate symbol has before and after symbols. Needed spaces is depend on * the symbol and defined in DVCharacterTable. @@ -51,14 +54,12 @@ private ValidationError validateSymbol(Sentence sentence, SymbolType symbolType) if (position != -1) { String key = ""; - if (position > 0 && symbol.isNeedBeforeSpace() - && !Character.isWhitespace(sentenceStr.charAt(position - 1))) { + if (position > 0 && symbol.isNeedBeforeSpace() && !isWhitespace(sentenceStr.charAt(position - 1))) { key = "Before"; } - if (position < sentenceStr.length() - 1 - && symbol.isNeedAfterSpace() - && !Character.isWhitespace(sentenceStr.charAt(position + 1))) { + if (position < sentenceStr.length() - 1 && symbol.isNeedAfterSpace() + && !isWhitespace(sentenceStr.charAt(position + 1)) && isLetterOrDigit(sentenceStr.charAt(position + 1))) { key += "After"; } diff --git a/redpen-core/src/test/java/cc/redpen/validator/sentence/SymbolWithSpaceValidatorTest.java b/redpen-core/src/test/java/cc/redpen/validator/sentence/SymbolWithSpaceValidatorTest.java index 12eaa0277..ef2e389b7 100644 --- a/redpen-core/src/test/java/cc/redpen/validator/sentence/SymbolWithSpaceValidatorTest.java +++ b/redpen-core/src/test/java/cc/redpen/validator/sentence/SymbolWithSpaceValidatorTest.java @@ -76,6 +76,20 @@ public void testNeedAfterSpace() throws RedPenException { assertEquals(10, errors.get(document).get(0).getStartPosition().get().offset); } + @Test + public void testDoNotNeedAfterSpaceAtTheEndOfSentence() throws RedPenException { + Document document = prepareSimpleDocument("Hello (world)."); + + config = Configuration.builder() + .addValidatorConfig(new ValidatorConfiguration("SymbolWithSpace")) + .addSymbol(new Symbol(RIGHT_PARENTHESIS, ')', "", false, true)) + .build(); + + RedPen redPen = new RedPen(config); + Map> errors = redPen.validate(singletonList(document)); + assertEquals(0, errors.get(document).size()); + } + @Test public void testNeedBeforeSpace() throws RedPenException { Document document = prepareSimpleDocument("I like her(Nancy) very much.");