Skip to main content
Question

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


lifalin2016
Contributor
Forum|alt.badge.img+29

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.

13 replies

david_r
Evangelist
  • 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
Contributor
Forum|alt.badge.img+29
  • Author
  • Contributor
  • August 22, 2018
david_r wrote:

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
Contributor
Forum|alt.badge.img+29
  • Author
  • Contributor
  • August 22, 2018
david_r wrote:

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
Evangelist
  • August 22, 2018
lifalin2016 wrote:
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
Contributor
Forum|alt.badge.img+29
  • Author
  • Contributor
  • August 24, 2018
david_r wrote:

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
Influencer
  • 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
Influencer
  • August 24, 2018
david_r wrote:

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
Contributor
Forum|alt.badge.img+29
  • Author
  • Contributor
  • August 28, 2018
takashi wrote:
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
Influencer
  • August 28, 2018
takashi wrote:
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
Contributor
Forum|alt.badge.img+29
  • Author
  • Contributor
  • August 29, 2018
takashi wrote:
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
Influencer
  • August 29, 2018
takashi wrote:
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
Contributor
Forum|alt.badge.img+29
  • Author
  • Contributor
  • August 29, 2018
takashi wrote:
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
Contributor
Forum|alt.badge.img+29
  • Author
  • Contributor
  • September 27, 2018
takashi wrote:
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 :-)

 

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings