Problem/Motivation
Find/Replace functions have a test to verify that the data is a string before acting on it. However when you try to parse an ID inside a feed and match it to a taxonomy term, the integer data will return an error "Input should be a string".
Steps to reproduce
Try to add a plugin FindReplace to a JSON feed with integer ID to match an existing taxonomy term name.
"category": {
"id": 123,
"label": "Feed category name "
},
So here we would like to replace 123 by our existing Taxonomy term "Website category A" so the match can be done whenever the label in the field would change.
Proposed resolution
Make a broader test to include numerics for those tests :
if (!is_string($data)) {
throw new TamperException('Input should be a string.');
}
Also should booleans be allowed too ?
Remaining tasks
Patch to review
User interface changes
None
API changes
None
Data model changes
None
Comments
Comment #2
tostinni commentedHere is a patch to allow numeric inside Find/Replace & sprintf plugins.
Comment #4
jamesdixon commentedThanks for the patch.
Looks like we need to update the test to check for the exception if it's not a string or numeric and check that the exception string is "Input should be a string or numeric." instead of the old value.
Comment #5
tostinni commentedHere is the new patch with the fixed test and also allowing numeric for StrPad plugin.
I don't think this need additional tests as the existing already cover the scope ?
Comment #6
jrochate commentedThanks. It works great.
An alternative could be a tamper to convert number to string, so we could cover these and other cases where the input is numeric.
Comment #7
nwom commentedThis worked perfectly. Thank you so much for the patch!
Comment #8
megachrizHere is the same, but with tests. Tests only patch should fail.
Comment #11
megachrizCommitted #8!
Comment #13
jrochate commentedActually I had to add a check for boolean value in order to work.
Something like the patch below, applied after the above commit.
Tamper was sending an error message on line 100, FindReplace, because of a value of "true" that wasn't numeric nor string.