Skip to main content
Question

Properly escaping string attribute values in custom Python transformer's setup dialog ?

  • August 17, 2018
  • 13 replies
  • 99 views

lifalin2016
Supporter
Forum|alt.badge.img+38

Hi.

I've just built a custom Python based transformer, which utilizes two string attribute values.

One of the string had some embedded quotes ("), which were stripped before given to the Python code.

I tried swapping the quotes with single-quotes, but that crashed the Python execution entirely.

Is there really no automatic escaping of the entered values (into the transformer setup dialog) before passing them on ?

I managed to get it working by entering \\" (backslash-quote) in place of " (quote), but that's really a bad work-around. FME should really do that automagically by itself.

Cheers.

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

13 replies

david_r
Celebrity
  • 8391 replies
  • August 17, 2018

It's difficult to say without knowing more about how you're using the string attribute values.

Could you please post a sample workspace or some sample code that reproduces the issue?


lifalin2016
Supporter
Forum|alt.badge.img+38
  • Author
  • Supporter
  • 592 replies
  • August 22, 2018

It's difficult to say without knowing more about how you're using the string attribute values.

Could you please post a sample workspace or some sample code that reproduces the issue?

Sure. My transformer is included.

 

test-prependappend-transformer.fmwt

 


lifalin2016
Supporter
Forum|alt.badge.img+38
  • Author
  • Supporter
  • 592 replies
  • August 22, 2018

It's difficult to say without knowing more about how you're using the string attribute values.

Could you please post a sample workspace or some sample code that reproduces the issue?

The values in the transformer in the submitted template are escaped. Remove the backslashes to see the failure.

 

 


david_r
Celebrity
  • 8391 replies
  • August 22, 2018
Sure. My transformer is included.

 

test-prependappend-transformer.fmwt

 

The linked custom transformer isn't available on my machine. You need to either post the transformer .fmx file here so I can install it, or embed the transformer into the workspace and repost.

lifalin2016
Supporter
Forum|alt.badge.img+38
  • Author
  • Supporter
  • 592 replies
  • August 24, 2018

It's difficult to say without knowing more about how you're using the string attribute values.

Could you please post a sample workspace or some sample code that reproduces the issue?

The transformer is included in the template. If this doesn't automatically make it available in the workspace, rename the .FMWT to .ZIP, and extract it from there.

 

 


takashi
Celebrity
  • 7842 replies
  • August 24, 2018
Hi @lifalin2016, found the fmx, py files.

 

I think the following modification could resolve the problem.

 

  • In the fmx file, change the parameter type to "TEXT_ENCODED" if the parameter value could contain some special characters, such as double quotation.
  • In the Python script, decode the encoded parameter value with fmeobjects.FMESession.decodeFromFMEParsableText method.

takashi
Celebrity
  • 7842 replies
  • August 24, 2018

It's difficult to say without knowing more about how you're using the string attribute values.

Could you please post a sample workspace or some sample code that reproduces the issue?

Hi @lifalin2016, found the fmx, py files.

 

I think the following modification could resolve the problem.

 

  • In the fmx file, change the parameter type to "TEXT_ENCODED" if the parameter value could contain some special characters, such as double quotation.
  • In the Python script, decode the encoded parameter value with fmeobjects.FMESession.decodeFromFMEParsableText method.

lifalin2016
Supporter
Forum|alt.badge.img+38
  • Author
  • Supporter
  • 592 replies
  • August 28, 2018
Hi @lifalin2016, found the fmx, py files.

 

I think the following modification could resolve the problem.

 

  • In the fmx file, change the parameter type to "TEXT_ENCODED" if the parameter value could contain some special characters, such as double quotation.
  • In the Python script, decode the encoded parameter value with fmeobjects.FMESession.decodeFromFMEParsableText method.
Hi Takashi.

 

Hmm, TEXT_ENCODED does not appear as a possible type in the docs about GUI-types !?

 

Is there another documentation to which only VIPs are privy ? :-)

 

Cheers

 

 


takashi
Celebrity
  • 7842 replies
  • August 28, 2018
Hi @lifalin2016, found the fmx, py files.

 

I think the following modification could resolve the problem.

 

  • In the fmx file, change the parameter type to "TEXT_ENCODED" if the parameter value could contain some special characters, such as double quotation.
  • In the Python script, decode the encoded parameter value with fmeobjects.FMESession.decodeFromFMEParsableText method.
Please read the documentation more carefully. You would find the description like this.

 

_ENCODED.

 

This suffix means the value of the parameter will be WWJD encoded. ...

 

 

 


lifalin2016
Supporter
Forum|alt.badge.img+38
  • Author
  • Supporter
  • 592 replies
  • August 29, 2018
Please read the documentation more carefully. You would find the description like this.

 

_ENCODED.

 

This suffix means the value of the parameter will be WWJD encoded. ...

 

 

 

Ah, I was concentrating on the left hand pane, not realizing that general suffix modifiers were defined. Thanks Takashi for sharing this insight.

 

What about the fmeobjects.FMESession.decodeFromFMEParsableText method ?

 

I can find it in the Python reference, but would never have looked for it under FMESession. What's the reason for it being "hidden" here ?

 

Cheers.

 


takashi
Celebrity
  • 7842 replies
  • August 29, 2018
Please read the documentation more carefully. You would find the description like this.

 

_ENCODED.

 

This suffix means the value of the parameter will be WWJD encoded. ...

 

 

 

Here.

 

http://docs.safe.com/fme/html/fmepython/api/fmeobjects/_utilities/fmeobjects.FMESession.decodeFromFMEParsableText.html#fmeobjects.FMESession.decodeFromFMEParsableText

 

 


lifalin2016
Supporter
Forum|alt.badge.img+38
  • Author
  • Supporter
  • 592 replies
  • August 29, 2018
Please read the documentation more carefully. You would find the description like this.

 

_ENCODED.

 

This suffix means the value of the parameter will be WWJD encoded. ...

 

 

 

FYI, the correct syntax is: fmeobjects.FMESession().decodeFromFMEParsableText(...)

 

 


lifalin2016
Supporter
Forum|alt.badge.img+38
  • Author
  • Supporter
  • 592 replies
  • September 27, 2018
Please read the documentation more carefully. You would find the description like this.

 

_ENCODED.

 

This suffix means the value of the parameter will be WWJD encoded. ...

 

 

 

I cannot accept your answer, until you've entered it as one such, Takashi :-)