Skip to content
Permalink
Browse files

Merge pull request #1514 from umple/semicolonHexCode

Semicolons in strings
  • Loading branch information...
TimLethbridge committed Nov 7, 2019
2 parents 546b8a0 + 24ad65a commit 6f2a036f3a4f99d1983222fd8ba068f9a444da12
@@ -109,6 +109,24 @@ class RuleBasedParser
return grootToken;
}

/*
This method helps to clean the string value of a token by tranforming an unicode character into its value. Such as semicolon "\u003B" into ";".
It supports \u003B ---> semicolon. This method can extended to support other unicode characters.
*/
private void cleanEscapeChars(Token token){

if(token.getValue() != null)
{
if(token.is("value") && token.getValue().contains("\\u003B"))
token.setValue(token.getValue().replace("\\u003B",";"));
}
for(Token subToken : token.getSubTokens())
{
cleanEscapeChars(subToken);
}

}

/*
Takes a root rule and uses it to start parsing. The result will be put into the root token passed. The parsing will be performed
on the file. data is a DataPackage which needs to be initialized(using the init(Position)) before passing to this function.
@@ -123,6 +141,7 @@ class RuleBasedParser
int parseResult = root.parse(token, 0,data.getInput().length(),data.getInput(),data);
if(parseResult==data.getInput().length())
{
cleanEscapeChars(token);cleanEscapeChars(token);
setRootToken(token);
}
else
@@ -152,6 +171,7 @@ class RuleBasedParser
int parseResult = root.parse(token, 0,data.getLine(line).length(),data.getLine(line),data);
if(parseResult==data.getInput().length())
{
cleanEscapeChars(token);
setRootToken(token);
}
else
@@ -327,6 +347,7 @@ class RuleBasedParser
}
analyzer.execute();
setRootToken(analyzer.getRootToken());
cleanEscapeChars(analyzer.getRootToken());
setParseResult(analyzer.getParseResult());
return getParseResult();
}
@@ -357,6 +378,7 @@ class RuleBasedParser

analyzer.execute();
setRootToken(analyzer.getRootToken());
cleanEscapeChars(analyzer.getRootToken());
setParseResult(analyzer.getParseResult());
return getParseResult();
}
@@ -3109,7 +3109,15 @@ public void conflictingModifiersForStateDependentMethods() {
public void validCodeInjection() {
assertHasNoWarningsParse("702_validCodeInjection.ump");
}

@Test
public void testSemicolonUnicode()
{
UmpleFile uFile = new UmpleFile(pathToInput,"classAttributeContainsSemicolons.ump");
UmpleModel umodel = new UmpleModel(uFile);
umodel.run();
String attributeValue = umodel.getUmpleClass(0).getAttribute(0).getValue().trim();
Assert.assertTrue(attributeValue.equals("\"int x =10 ; x++ ;\""));
}
public boolean parse(String filename)
{
//String input = SampleFileWriter.readContent(new File(pathToInput, filename));
@@ -0,0 +1,6 @@
class AttriWithSemicolons
{

String aJavaStatement = "int x =10 \u003B x++ \u003B" ;

}

0 comments on commit 6f2a036

Please sign in to comment.
You can’t perform that action at this time.