Link with some unknow string when parameter exist - jsf

I have some strange issue, when try to set parameter in string(redirect). I don't know where the last chars came from
public String register(){
// ...
return "/login?correctReg=true?faces-redirect=true&includeViewParams=true";
}
And output link:
.../login.xhtml?correctReg=true%3F
Where this %3F came from?

The second ? after correctReg=true is encoded automatically to %3f. You probably mean...
return "/login?correctReg=true&faces-redirect=true&includeViewParams=true";
... with &.

Related

Flutter | How to check if String does not contain a substring or a character

I'm learning Flutter/Dart and there is this check that i want to perform - to validate that a user who has entered an email should contain # in it
String myString = 'Dart';
// just like i can do the following check
myString.contains('a') ? print('validate') : print('does not validate')
// I want to do another check here
myString does not contain('#') ? print('does not validate'): print('validate')
Can someone suggest is there any inbuilt function to do such a thing.
Just simply put not ! operator (also known as bang operator on null-safety) on start
void main() {
String myString = 'Dart';
// just like i can do the following check
myString.contains('a') ? print('validate') : print('does not validate');
// I want to do another check here
!myString.contains('#') ? print('does not validate') : print('validate');
}

Mule Groovy string replace payload contains question marks

String header = "EXL=TST+​[Placeholder1]​+[Placeholder2]+[Placeholder3]​:[Placeholder2]​"
header = header.replaceAll("\\[Placeholder1\\]", escapeEdi((String)${propertyVal1}))
header = header.replaceAll("\\[Placeholder2\\]", escapeEdi((String)${propertyVal2}))
header = header.replaceAll("\\[Placeholder3\\]", escapeEdi((String)${propertyVal3}))
println(header)
String escapeEdi(String target){
StringBuilder result = new StringBuilder();
for(char c : target.toCharArray()){
switch(c){
case '+':
case ':':
case '\'':
case '?':
result.append("?");
default:
result.append(c);
}
}
return result.toString();
}
With the above sample code, I'm getting the payload result with a lot of question marks within it:
Example payload:
EXL=TST+​1+?1234?+1234+123?:123?+?1-1-170101?++?TEST?'
Even removing the escapeEdi function nets the exact same result. I'm not even sure if the escape edi is needed, and frankly none of the values passed have any such characters, purely alphanumeric.
Because of the ?, it's causing the message to be sent with a UTF-8-BOM, and their end is just not designed to handle it, which means it must be cleared and removed on my end. How can I get rid of all these ?
A simple replaceAll with an empty string didn't work.
Trying to escapeEdi() at the end of the result didn't do anything either, and I have a very similar script to this which works just fine, no silly character included. What might be causing this issue?
the funny thing )
the following code
String header = "EXL=TST+​[Placeholder1]​+xxx"
header = header.replaceAll("\\[Placeholder1\\]", "val1")
println header
produces
EXL=TST+?val1?+xxx
and finally i found that there is a strange spaces before and after [] in your source string with uni-code value (8203)
and it is Unicode Character 'ZERO WIDTH SPACE' (U+200B)
see on the screenshot in green:

IwNUI CTextFieldPtr to string

I'm using a IwNUI CTextFieldPtr control and I would like to store/use the text attribute stored on the object in a string variable. I need to use that string but I have no clue on the documentation or examples on how to do it... I don't have a complete code sample either because what I'm asking should be pretty straight forward, such as:
CTextFieldPtr login_tUsername;
//textfield init here
std::string c_username;
login_tUsername->GetAttribute("text", c_username);
Please help me, thank you very much!
And other approach, would be something like this, which is by far much closer to what I wanted to do:
CString value;
login_tUsername->GetAttribute("text", value);
std::string thestring = value.Get();
:)
(Credit goes billarhos billarhos)
Well... the best solution I found for this problem was something like this:
login_tUsername->SetEventHandler("textchanged", this, &OnUserEdit);
bool OnUserEdit(CTextField* textField, const char* text)
{
c_username = text;
return true;
}
I don't know why, but it seems you cannot use the textbox text attribute directly.
Cheers!

as3, string to variable

I have array with variable names:
var subjectArray:Array=["subject0","subject1","subject2"];
I need to convert string to var, but following does not work: this[subjectArray[0]] throws an error.
Any thoughts?
That syntax should work. You can check if an object contains a property with a given name with the in keyword. The property does probably not exist.
if (subjectArray[0] in this) {
// do something with this[subjectArray[0]];
}

preg_replace: reference object in replacement

Do you know of any way to reference an object in the replacement part of preg_replace. I'm trying to replace placeholders (delimited with precentage signs) in a string with the values of attributes of an object. This will be executed in the object itself, so I tried all kinds of ways to refer to $this with the /e modifier. Something like this:
/* for instance, I'm trying to replace
* %firstName% with $this->firstName
* %lastName% with $this->lastName
* etc..
*/
$result = preg_replace( '~(%(.*?)%)~e', "${'this}->{'\\2'}", $template );
I can't get any variation on this theme to work. One of the messages I've been getting is: Can't convert object Model_User to string.
But of course, it's not my intention to convert the object represented by $this to a string... I want to grab the attribute of the object that matches the placeholder (without the percentage signs of course).
I think I'm on the right track with the /e modifier. But not entirely sure about this either. Maybe this can be achieved much more simple?
Any ideas about this? Thank you in advance.
Like I commented to Paul's answer: in the meanwhile I found the solution myself. The solution is much more simple than I thought. I shouldn't have used double quotes.
The solution is as simple as this:
$result = preg_replace( '~(%(.*?)%)~e', '$this->\\2', $template );
Hope this helps anyone else for future reference.
Cheers.
Check out preg_replace_callback - here's how you might use it.
class YourObject
{
...
//add a method like this to your class to act as a callback
//for preg_replace_callback...
function doReplace($matches)
{
return $this->{$matches[2]};
}
}
//here's how you might use it
$result = preg_replace_callback(
'~(%(.*?)%)~e',
array($yourObj, "doReplace"),
$template);
Alternatively, using the /e modifier, you could maybe try this. I think the only way to make it work for your case would be to put your object into global scope
$GLOBALS['yourObj']=$this;
$result = preg_replace( '~(%(.*?)%)~e', "\$GLOBALS['yourObj']->\\2", $template );

Resources