Skip to content

Commit 3df492b

Browse files
committed
fixes #329
1 parent 2acaee0 commit 3df492b

File tree

3 files changed

+115
-30
lines changed

3 files changed

+115
-30
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@
1717
*.jj~
1818
*.java~
1919
*.yml~
20+
/nbproject/

src/main/java/net/sf/jsqlparser/expression/StringValue.java

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,40 +26,44 @@
2626
*/
2727
public class StringValue implements Expression {
2828

29-
private String value = "";
29+
private String value = "";
3030

31-
public StringValue(String escapedValue) {
32-
// romoving "'" at the start and at the end
33-
value = escapedValue.substring(1, escapedValue.length() - 1);
34-
}
31+
public StringValue(String escapedValue) {
32+
// romoving "'" at the start and at the end
33+
if (escapedValue.startsWith("'") && escapedValue.endsWith("'")) {
34+
value = escapedValue.substring(1, escapedValue.length() - 1);
35+
} else {
36+
value = escapedValue;
37+
}
38+
}
3539

36-
public String getValue() {
37-
return value;
38-
}
40+
public String getValue() {
41+
return value;
42+
}
3943

40-
public String getNotExcapedValue() {
41-
StringBuilder buffer = new StringBuilder(value);
42-
int index = 0;
43-
int deletesNum = 0;
44-
while ((index = value.indexOf("''", index)) != -1) {
45-
buffer.deleteCharAt(index - deletesNum);
46-
index += 2;
47-
deletesNum++;
48-
}
49-
return buffer.toString();
50-
}
44+
public String getNotExcapedValue() {
45+
StringBuilder buffer = new StringBuilder(value);
46+
int index = 0;
47+
int deletesNum = 0;
48+
while ((index = value.indexOf("''", index)) != -1) {
49+
buffer.deleteCharAt(index - deletesNum);
50+
index += 2;
51+
deletesNum++;
52+
}
53+
return buffer.toString();
54+
}
5155

52-
public void setValue(String string) {
53-
value = string;
54-
}
56+
public void setValue(String string) {
57+
value = string;
58+
}
5559

56-
@Override
57-
public void accept(ExpressionVisitor expressionVisitor) {
58-
expressionVisitor.visit(this);
59-
}
60+
@Override
61+
public void accept(ExpressionVisitor expressionVisitor) {
62+
expressionVisitor.visit(this);
63+
}
6064

61-
@Override
62-
public String toString() {
63-
return "'" + value + "'";
64-
}
65+
@Override
66+
public String toString() {
67+
return "'" + value + "'";
68+
}
6569
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright (C) 2016 JSQLParser.
3+
*
4+
* This library is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU Lesser General Public
6+
* License as published by the Free Software Foundation; either
7+
* version 2.1 of the License, or (at your option) any later version.
8+
*
9+
* This library is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public
15+
* License along with this library; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17+
* MA 02110-1301 USA
18+
*/
19+
package net.sf.jsqlparser.expression;
20+
21+
import org.junit.After;
22+
import org.junit.AfterClass;
23+
import org.junit.Before;
24+
import org.junit.BeforeClass;
25+
import org.junit.Test;
26+
import static org.junit.Assert.*;
27+
28+
/**
29+
*
30+
* @author toben
31+
*/
32+
public class StringValueTest {
33+
34+
public StringValueTest() {
35+
}
36+
37+
@BeforeClass
38+
public static void setUpClass() {
39+
}
40+
41+
@AfterClass
42+
public static void tearDownClass() {
43+
}
44+
45+
@Before
46+
public void setUp() {
47+
}
48+
49+
@After
50+
public void tearDown() {
51+
}
52+
53+
54+
@Test
55+
public void testGetValue() {
56+
StringValue instance = new StringValue("'*'");
57+
String expResult = "*";
58+
String result = instance.getValue();
59+
assertEquals(expResult, result);
60+
}
61+
62+
@Test
63+
public void testGetValue2_issue329() {
64+
StringValue instance = new StringValue("*");
65+
String expResult = "*";
66+
String result = instance.getValue();
67+
assertEquals(expResult, result);
68+
}
69+
70+
/**
71+
* Test of getNotExcapedValue method, of class StringValue.
72+
*/
73+
@Test
74+
public void testGetNotExcapedValue() {
75+
StringValue instance = new StringValue("'*''*'");
76+
String expResult = "*'*";
77+
String result = instance.getNotExcapedValue();
78+
assertEquals(expResult, result);
79+
}
80+
}

0 commit comments

Comments
 (0)