Why Pound symbol (£) is converted to question mark (?) in Postman? - java

I have set some error code and message in a JSON file in my project which looks like (not original code for safety):
{
"ERROR":"Limit is £100."
}
When I set this message to be thrown as exception when testing from Postman, instead of showing Limit is £100., it shows like Limit is ?100.
So, I'm worried why £ gets converted to ?. Then, I tried to replace this ? with £ by using below code:
String message = fetchErrorMessage("ERROR", ***some parameters***);
if (message != null) {
message = message.contains("�")
? message.replaceAll("�", "£")
: message;
}
Note: I checked with � instead of ? because when I was debugging the code and hover over the message to check whether it contains the £ symbol or not, I found that it was having a weird looking square block (check screenshot below). So, I copy-paste it and got to know it's a question mark symbol inside a black diamond.
Now, with above piece of code change, the message is coming properly in Postman but soon I realized that when I deployed the code in UAT environment, it still shows ?.
So, any workaround how to fix it?

There is a specific character that shows up wrong when UTF-8 is set from the client(SoapUI) in the header content-type: application/json;charset=UTF-8.
For more details Check this link

Related

How to debug a JSON error (occuring in Wordpress Backend)?

I am experiencing a problem with Wordpress.
Everything seems to work fine, but with the usage of some (3rd-party)-Blocks in the Gutenberg-editor, something is causing an issue, I assume with Java.
If the content in Wordpress is saved, an error occurs:
Updating failed. The response is not a valid JSON response.
There is not more to the error. Debug enabeling in wp-config does not log any errors. If I am right, this is correct, because this debug-function in WP would only log php related issues.
On the Internet there are all kinds of random solutions to fix this error (change permalinks as an example). Does not do anything for me. More random solutions are deactivating all plugins. Still, the issue persists. Update Wordpress and php. Done. Error persists.
All the above seems to be "searching in the dark". So I would like to know, how to find out, what the acutal issue is. Surely, there must be some kind of debugging?
I found something somewhere on the net in regards to get the last JSON-error from the server:
if (!function_exists('json_last_error_msg')) {
function json_last_error_msg() {
static $ERRORS = array(
JSON_ERROR_NONE => 'No error',
JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
JSON_ERROR_STATE_MISMATCH => 'State mismatch (invalid or malformed JSON)',
JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded',
JSON_ERROR_SYNTAX => 'Syntax error',
JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded'
);
$error = json_last_error();
return isset($ERRORS[$error]) ? $ERRORS[$error] : 'Unknown error';
}
}
?>
If I understood this right, the above code should go in a .php-file, which I call trough the browser. Did it, tried it. Browser window remains just blank. So either this is not working for me, or there is just no error stored?
Who can point me in the right direction?
I also did create two test pages in WP, and tried to save both. One without the error causing element, and one with. Both attempts have been logged, using the Borwser's Developer-Tools on the "network" tab. If anybody thinks, this would be of help to evaluate the issue, let me know and I will upload them.

How do ReactionEmojis work in discord4j 3.1.0

I'm currently working on a bot with discord4j where I want to add a reaction(emoji) to a message.
But i have no clue, how to use the addReaction() method and every example i find is using an older version.
In earlier versions of dicord4j you could give a string of the unicode representation of the emoji as the parameter, but now it just takes in an object of the type ReactionEmoji. I looked at its methods nothing really makes sense except the ReactionEmoji.unicode(String raw) but then i get the error-message "unknown emoji". As input of the string i tried the unicode, the actual emoji itself, and i went into debug mode, added a reaction to a message, then took the reaction in debug mode, and copied the raw value of the reaction, pasted it as the input parameter of the unicode() mehtod , but it still didn't recognize it as an emoji.
Is there some documentation i can't find?
My code :
Message msg = channel.createMessage("Test").block();
msg.addReaction("U+2B06").block();
You have to use a unicode escape instead:
channel.createMessage("Test")
.flatMap(msg -> msg.addReaction(ReactionEmoji.unicode("\u2B06")))
.subscribe();
For documentation refer to addReaction and ReactionEmoji
For multiple reactions
channel.createMessage("Test").flatMap(msg ->
msg.addReaction(ReactionEmoji.unicode("🛑"))
.then(msg.addReaction(ReactionEmoji.unicode("🪂"))))
.subscribe();

ESAPI not passing file validation

I am working with ESAPI to try and validate windows directory paths. For some reason, the part of my directory path named \14\ is getting converted into a CRLF. The error I am receiving is below, what am I not understanding correctly? I feel like my regex should be working.
WARN IntrusionDetector [SECURITY FAILURE Anonymous:null#unknown -> /project-test/IntrusionDetector] Invalid input: context=directoryPath, type(DirectoryName)=^[a-zA-Z0-9:/\\!##$%^&{}\[\]()_+\-=,.~'` ]{1,255}$, input=C:\UsersTESTUS~1AppDataLocalTempTestCase8002TempWorkSpace, orig=C:\Users\TESTUS~1\AppData\Local\Temp\14\TestCase8002TempWorkSpace
As you can see, I am using the regex:
^[a-zA-Z0-9:/\!##$%^&{}[]()_+-=,.~'` ]$
My input is:
C:\Users\TESTUS~1\AppData\Local\Temp\14\TestCase8002TempWorkSpace
Ouput, after ESAPI does canonicalization and validation:
C:\UsersTESTUS~1AppDataLocalTempTestCase8002TempWorkSpace
Here is the line of code that causes me to receive the error;
String validatedSourcePath = ESAPI.validator().getValidInput("directoryUnzip", directory, "DirectoryName", 255, false);
File validFile = new File(validatedSourcePath);
#C.Williams: I was about 30 minutes into writing up a detailed reply in an editor and accidentally excited my editor window. I'm too ticked off at my stupidity of not saving it to write it again, especially since I was only about 75% done.
However, if you want to email me I can arrange to talk to you via Google Hangouts or Signal to tell you want your problem is and how you can fix it. But it's long and complicated and partially related to a bug the ESAPI team just fixed but is not in any official release yet. But I am not going to take another 45 minutes or more trying to reply with any written text. My email address should be easy enough to find. Just google for my name and ESAPI. I am one of the project co-leaders on ESAPI.
-kevin wall

Message Manager displays messages only as field decorators and not in header

I am using the Eclipse MessageManager to provide error messages in case of invalid input. For example:
mmng.addMessage("textLength", "blah", null, IMessageProvider.ERROR, field);
I do this twice. Once inside an instance of ModifyListener and once just right after the creation of the Text field in order to validate input on load.
The MessageManager displays an error in the header of the page as well as next to the text field (decorator) when calling the addMessage method inside the modifyEvent method of an child instance of ModifyListener. However, when adding the message right after the creation of the text field, only a decorator will be displayed (no errors in the header saying that "n errors detected").
I am wondering why this happens. I tested this with the Eclipse ProductEditor and there's actually a similar behavior. The errors won't appear in the header if you open a .product file that has on the first page an error (only the decorator will appear). However, when switching to other pages and then switching back to this particular page, the error in the header will appear. Unfortunately, this is not the case on my side. I would be satisfied if I could implement the same behavior, even though the best case would be to automatically display errors on both locations, in the header and next to the field as a decorator.
I also tried to solve this issue by calling the update() method of the MessageManager instance, but unfortunately, that did not solve the mystery.
By the way, I am using Eclipse Luna 2.
I debugged the MessageManager class and noticed the following condition inside the update method:
if (form.getHead().getBounds().height == 0 || mergedList.isEmpty() || mergedList == null) {
form.setMessage(null, IMessageProvider.NONE);
return;
}
Besides that a NPE will be thrown when mergedList is null, this condition seems really strange to me. However, setting the height of head solved my problem:
form.getForm().getHead().setBounds(0, 0, 0, 1);

Selenium + Java = Assertion error

I already have this kind of error, and I still don't know why. What am I doing wrong?
I need to assert true if I get a text in the page source.
So here is my method:
public boolean AssertSearch() {
return driver.getPageSource().contains("Item found");
}
And here is my assert:
assertTrue(buscarnok.validabuscaNOK());
And I keep receiving the message "Assertion Error". I don't know why. If I change the "return driver.getPageSource().contains("Item found");"to driver.findelement(by.id("someID")).isdisplayed();it works fine, so why isn't it working with getpagesource?
If the text you are looking for is not initially in the page or if it is hidden, it may not find it.
Try something like this:
String bodyText = driver.findElement(By.tagName("body")).getText();
Assert.assertTrue("Item Found", bodyText.contains(text));
You can narrow down the search by selecting a different tag name or even a div by its class or id

Categories

Resources