diff --git a/pmd-objectivec/etc/grammar/ObjC2.0.jj b/pmd-objectivec/etc/grammar/ObjC2.0.jj index ba888ee9ed..f25936bdfa 100644 --- a/pmd-objectivec/etc/grammar/ObjC2.0.jj +++ b/pmd-objectivec/etc/grammar/ObjC2.0.jj @@ -375,8 +375,8 @@ TOKEN : { | )? (["f","F","d","D"])? | "." (["0"-"9"])+ ()? (["f","F","d","D"])? | (["0"-"9"])+ (["f","F","d","D"])? | (["0"-"9"])+ ()? ["f","F","d","D"]> | <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+> | -| -| +| +| } TOKEN : diff --git a/pmd-objectivec/src/test/java/net/sourceforge/pmd/cpd/UTF8EscapesInStringLiteralObjCTokenizerTest.java b/pmd-objectivec/src/test/java/net/sourceforge/pmd/cpd/UTF8EscapesInStringLiteralObjCTokenizerTest.java new file mode 100644 index 0000000000..bd3d87d930 --- /dev/null +++ b/pmd-objectivec/src/test/java/net/sourceforge/pmd/cpd/UTF8EscapesInStringLiteralObjCTokenizerTest.java @@ -0,0 +1,37 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ +package net.sourceforge.pmd.cpd; + +import java.io.IOException; + +import net.sourceforge.pmd.testframework.AbstractTokenizerTest; + +import org.apache.commons.io.IOUtils; +import org.junit.Before; +import org.junit.Test; + + +//Tests if the ObjectiveC tokenizer supports UTF-8 escapes in string literals +public class UTF8EscapesInStringLiteralObjCTokenizerTest extends AbstractTokenizerTest { + + private static final String FILENAME = "FileWithUTF8EscapeInStringLiteral.m"; + + @Before + @Override + public void buildTokenizer() throws IOException { + this.tokenizer = new ObjectiveCTokenizer(); + this.sourceCode = new SourceCode(new SourceCode.StringCodeLoader(this.getSampleCode(), FILENAME)); + } + + @Override + public String getSampleCode() throws IOException { + return IOUtils.toString(ObjectiveCTokenizer.class.getResourceAsStream(FILENAME), "UTF-8"); + } + + @Test + public void tokenizeTest() throws IOException { + this.expectedTokenCount = 45; + super.tokenizeTest(); + } +} diff --git a/pmd-objectivec/src/test/resources/net/sourceforge/pmd/cpd/FileWithUTF8EscapeInStringLiteral.m b/pmd-objectivec/src/test/resources/net/sourceforge/pmd/cpd/FileWithUTF8EscapeInStringLiteral.m new file mode 100644 index 0000000000..dafd9e3c88 --- /dev/null +++ b/pmd-objectivec/src/test/resources/net/sourceforge/pmd/cpd/FileWithUTF8EscapeInStringLiteral.m @@ -0,0 +1,8 @@ +@property (nonatomic, strong) UIButton *copyrightsButton; + +- (void)setupCopyrightsButton { + self.copyrightsButton = [[UIButton alloc] initWithFrame:CGRectZero]; + [self.copyrightsButton setTitle:@"\u00a9" forState:UIControlStateNormal]; +} + +@end diff --git a/src/site/markdown/overview/changelog.md b/src/site/markdown/overview/changelog.md index ca78f966a6..1789a772a6 100644 --- a/src/site/markdown/overview/changelog.md +++ b/src/site/markdown/overview/changelog.md @@ -19,6 +19,7 @@ * [#29](https://github.com/adangel/pmd/pull/29): Added support for files with UTF-8 BOM to JSP tokenizer. * [#30](https://github.com/adangel/pmd/pull/30): Removed file filter for files that are explicitly specified on the CPD command line using the '--files' command line option. * [#31](https://github.com/adangel/pmd/pull/31): Added file encoding detection to CPD. +* [#32](https://github.com/adangel/pmd/pull/32): Extended Objective-C grammar to accept UTF-8 escapes (\uXXXX) in string literals. * [#79](https://github.com/pmd/pmd/pull/79): do not flag public static void main(String[]) as UseVarargs; ignore @Override for UseVarargs * [#80](https://github.com/pmd/pmd/pull/80): Update mvn-plugin.md * [#83](https://github.com/pmd/pmd/pull/83): Adds new Code Climate-compliant JSON renderer