Skip to content

Commit

Permalink
Fixed #240 : Double Quotes aren't escaped.
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanue1 committed May 18, 2019
1 parent d850ec4 commit e986b29
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ private void parseLDC(DefaultStack<Expression> stack, ConstantPool constants, in
break;
case Constant.CONSTANT_String:
int stringIndex = ((ConstantString)constant).getStringIndex();
stack.push(new StringConstantExpression(lineNumber, StringUtil.escapeString(constants.getConstantString(stringIndex))));
stack.push(new StringConstantExpression(lineNumber, constants.getConstantString(stringIndex)));
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@
* copy and modify the code freely for non-commercial purposes.
*/

package org.jd.core.v1.service.converter.classfiletojavasyntax.util;
package org.jd.core.v1.service.fragmenter.javasyntaxtojavafragment.util;


public class StringUtil {

public static String escapeString(String s) {
int length = s.length();
int i = 0;

for (; i < length; i++) {
for (int i = 0; i < length; i++) {
char c = s.charAt(i);

if ((c == '\\') || (c < ' ')) {
StringBuilder sb = new StringBuilder(length * 2 + 2);
if ((c == '\\') || (c == '"') || (c < ' ')) {
StringBuilder sb = new StringBuilder(length * 2);

sb.append(s.substring(0, i));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.jd.core.v1.service.converter.classfiletojavasyntax.util.PrimitiveTypeUtil;
import org.jd.core.v1.service.fragmenter.javasyntaxtojavafragment.util.CharacterUtil;
import org.jd.core.v1.service.fragmenter.javasyntaxtojavafragment.util.JavaFragmentFactory;
import org.jd.core.v1.service.fragmenter.javasyntaxtojavafragment.util.StringUtil;
import org.jd.core.v1.util.DefaultList;

import java.util.HashSet;
Expand Down Expand Up @@ -529,7 +530,7 @@ public void visit(PreOperatorExpression expression) {
@Override
public void visit(StringConstantExpression expression) {
tokens.addLineNumberToken(expression);
tokens.add(new StringConstantToken(expression.getString(), currentInternalTypeName));
tokens.add(new StringConstantToken(StringUtil.escapeString(expression.getString()), currentInternalTypeName));
}

@Override
Expand Down

0 comments on commit e986b29

Please sign in to comment.