Merge branch 'pr-1754'

This commit is contained in:
Andreas Dangel
2019-04-05 14:11:21 +02:00
4 changed files with 39 additions and 2 deletions

View File

@ -16,6 +16,8 @@ This is a {{ site.pmd.release_type }} release.
### Fixed Issues
* go
* [#1751](https://github.com/pmd/pmd/issues/1751): \[go] Parsing errors encountered with escaped backslash
* java
* [#1729](https://github.com/pmd/pmd/issues/1729): \[java] JavaRuleViolation loses information in `className` field when class has package-private access level
* java-bestpractices

View File

@ -917,10 +917,10 @@ RUNE_LIT
//unicode_value = unicode_char | little_u_value | big_u_value | escaped_char .
fragment UNICODE_VALUE
: UNICODE_CHAR
| LITTLE_U_VALUE
: LITTLE_U_VALUE
| BIG_U_VALUE
| ESCAPED_CHAR
| UNICODE_CHAR
;
//byte_value = octal_byte_value | hex_byte_value .

View File

@ -0,0 +1,29 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.cpd;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
public class EdgeCasesTokenizerTest {
private String getSampleCode(final String filename) throws IOException {
return IOUtils.toString(GoTokenizer.class.getResourceAsStream(filename), StandardCharsets.UTF_8);
}
@Test
public void testEscapedBackSlash() throws IOException {
// See https://github.com/pmd/pmd/issues/1751
final String filename = "issue1751.go";
final GoTokenizer tokenizer = new GoTokenizer();
final SourceCode sourceCode = new SourceCode(new SourceCode.StringCodeLoader(getSampleCode(filename), filename));
final Tokens tokens = new Tokens();
tokenizer.tokenize(sourceCode, tokens); // it should simply not fail
}
}

View File

@ -0,0 +1,6 @@
func test(in *Value, param *Value) (*Value, *Error) {
output := strings.Replace(in.String(), "\\", "\\\\", -1)
output = strings.Replace(output, "\"", "\\\"", -1)
output = strings.Replace(output, "'", "\\'", -1)
return AsValue(output), nil
}