Opened 4 years ago

Last modified 2 years ago

#4867 assigned defect

Incorrect handling of escaped strings in the compiler

Reported by: jsten Owned by: Jesper Mattsson
Priority: major Milestone: 2.0.x
Component: Modelica/FrontEnd Version: trunk
Keywords: Cc: Johan Ylikiiskilä


It seems that we handle escaping of string incorrectly in the compiler. The internal string that is stored is already escaped which causes problem when the string is retrieved from a scripting environment, such as Python. Instead the string should be stored unescaped and then it should be escaped when needed.

Example of this:

model test
    parameter String s = "b\"b";
end test;
from pymodelica.compiler_wrappers import ModelicaCompiler

mc = ModelicaCompiler()
source_root = mc.parse_model("")
target = mc.create_target_object("me", "1.0")
inst_node = mc.instantiate_model(source_root,"test", target)
s = inst_node.genericLookupInstComponent("s").target()
s_val = s.ceval()
print s_val.stringValue()

Console output:

In [1]: run

In [2]: s_val.stringValue()
Out[2]: u'b\\"b'

Change History (1)

comment:1 Changed 2 years ago by Jesper Mattsson

Owner: set to Jesper Mattsson
Status: newassigned
Note: See TracTickets for help on using tickets.