You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is an issue when we have to unwrap characters at the start or at the end only. I am highlighting 4 issues in below examples.
%dw 2.0
import unwrap from dw::core::Strings
output application/json
---
{
"a": unwrap(null, ""),
"b": unwrap(null, '\0'),
"c": unwrap("'abc'", "'"),
"d": unwrap("AABabcBAA", 'A'),
"e": unwrap("A", '#'),
"f": unwrap("#A", '#'), //current ouptut is "A#", which is wrong and this is not available in input also. Output should be "A"
"g": unwrap("A#", '#') // current output is "#A", which is wrong and this is not available in input also. Output should be "A",
"h": unwrap("ABC", 'A'), //current output is "B", which is wrong, it should not remove C from the input.
"i": unwrap("ABC",'C') //current output is "B", which is wrong, it should not remove A from the input.
}
My suggestion will be to update the unwrap function to consider the wrapping characters from the end or start. I have the below suggestions.
fun unwrap(text: String, wrapper: String): String = do {
if(!startsWith(text, wrapper) and !endsWith(text, wrapper))
text
else if(startsWith(text, wrapper) and !endsWith(text, wrapper))
text[1 to -1]
else if(!startsWith(text, wrapper) and endsWith(text, wrapper))
text[0 to -2]
else
text[1 to -2] default text
}
The text was updated successfully, but these errors were encountered:
Hi @shyamrajprasad though the bug you are reporting does exits, I don't think that the solution is the one I would suggest. For me it should only remove or unwrap if it starts and ends with the specified character.
So I would propose
@Since(version = "2.2.0")
fun unwrap(text: String, wrapper: String): String = do {
if(!startsWith(text, wrapper) or !endsWith(text, wrapper)) //changing from and to or
text
else
text[1 to -2] default text
}
There is an issue when we have to unwrap characters at the start or at the end only. I am highlighting 4 issues in below examples.
My suggestion will be to update the unwrap function to consider the wrapping characters from the end or start. I have the below suggestions.
The text was updated successfully, but these errors were encountered: