Question

Suspicious Behavior of StringReplacer

  • 4 November 2018
  • 3 replies
  • 0 views

Userlevel 2
Badge +17

From this Q&A: Replace attribute values for all attributes

My first idea was to use a StringReplacer to replace every attribute with '0' if it matched the regex '^0*$' (0 or more '0'), '1' otherwise.

I thought it should work theoretically, but the StringReplacer replaced '0' with '1' in fact.

If you set a character (e.g. 'x') other than '0' to the Replacement Text parameter, it worked fine.

I'm afraid that there could be a bug here. See also the attached workspace.

(FME 2018.1.0.3)

Original:

Unexpected Result: Every <empty> was replace with '0', but '0' was replaced with '1'.

Comparison: Every '0' and <empty> was replaced with 'x'.


3 replies

Userlevel 4
Badge +13

Well I've just spent some time looking at this and trying a few things, and indeed, you seem to be right.

 

I find the same thing happens with a single "1" being replaced by "1" as well. So it is something about a single digit being replaced by the same thing causing us to think we haven't done anything to the text.

 

And as I typed that I figured out the issue. IF we replace with EXACTLY what was there to begin with, we THINK WE DID NOT DO ANYTHING!!! So then we go to the "expression not found" case. Clearly a bug. See my example below -- especially the very last string replacer where I replace "dale" with "dale" only to be told that no replacement was made. Very good catch Takashi!

smallreplacementtest.fmw

Userlevel 4
Badge +13

Hi @takashi. Our developer Shelley has reported this as fixed in version 5 of the transformer in FME 2019. To get the fix, please upgrade the transformer after opening your workspace in FME 2019.

Userlevel 2
Badge +17

Hi @takashi. Our developer Shelley has reported this as fixed in version 5 of the transformer in FME 2019. To get the fix, please upgrade the transformer after opening your workspace in FME 2019.

Thanks for the fix!

Reply