ajax(search suggest) funny character problem - ajax

ajax(search suggest), if input funny character(like Ô) and submit it, "?" is displayed in *****.asp. ( response.write (request.form("str")))
i am using
xmlhttp.open("post", "*****.asp", true);
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded; charset=UTF-8');
xmlhttp.send("str="+escape($("str").value));
and there is <%#CODEPAGE=65001%> in *****.asp file
How can i get the correct word--- "Ô" in *****.asp

escape() is terrible, avoid it at all costs. Try this:
xmlhttp.send("str="+encodeURIComponent($("str").value));
This would encode Ô into %C3%94 - assuming the page decoding it supports utf8 you should be fine.

Related

Wrong filename when downloading file whose name contains double quote(") from Springboot server

The code for setting filename for the file to be downloaded :
String originalFileNameDecoded = URLDecoder.decode(originalFileName, "UTF-8");
URI uri = new URI(null, null, originalFileNameDecoded, null);
return ResponseEntity.ok()
.header("Content-Disposition", "attachment; filename=\"" + uri.toASCIIString() + "\"")
.contentLength(resource.contentLength())
.contentType(org.springframework.http.MediaType.APPLICATION_OCTET_STREAM)
.body(resource);
The reason why first decode the filename is because the originalFileName may contains URL encoded characters.
For files with regular names (only number and English letter), it works fine. However, when I try to download a file with name like pic201;9050.814,3"731(copy).png in the browser (chrome on linux), the filename becomes pic201;9050.814,3_731(copy).png.
I used to believe it is the browser behaviour, but I tried it in Edge and the same situation happened again.
So I wonder if there is something wrong with my code or something else happened.

encoding problem for SUBJECT of email using CDO

Using vbscript (asp) with CDO I have problem with encoding in SUBJECT of email. I have used two solutions for BODY part of email and both works but non of them works for SUBJECT part.
First solution: Endcoding characters of email BODY using chrw (not working for subject):
for x=1567 to 1785
encoded="&#" & x & ";"
Body= Replace(Body, chrw(x), encoded, 1, -1, 1)
next
Second solution: setting HTMLBodyPart encoding:
objMessage.HTMLBodyPart.Charset = "utf-8"
is there something similar for SUBJECT part of email (e.g. objMessage.SubjectPart.Charset)?
Try:
objMessage.TextBodyPart.Charset = "utf-8"
or simply:
objMessage.BodyPart.Charset = "utf-8"
It has been documented elsewhere that modifying the Charset of the TextBodyPart also impacts (the plain/text) Subject.
Hope this helps.

Rack cookies and ruby strings

I'm trying to decode a cookie and the interpreter is escaping backslashes that I need to remain intact.
This works
encrypted = %Q{"pgmQKWFl3ZqLWjMR6HISwjzbTSbF3qNj/xABLuR7sTRhG4hhVFDUBhrWLpHyXjOR0I9UB8zpzyOT\012J0RDv0s9QcJgm5kx0+pPZFmIt/dfv5LH0UIYvEmODnbfqpzjV7uIgpoi+fdVJQaHwk1GF5W1F3hg\0122pWmc/aDz8saLG4j5I4U+cctEo7uUOOKn2xRszlytNIOylFQramG1UKC6TLFrkXjz24/MEfEPbaO\012pHa2dzYbKN+2AOACVrspysnnAeG0W97EvaV9Q3OXdIY/9eElpLzrbgf+4weTG/qRTd7iSjautF0G\0129KMpzusxQxEI6hSrq+aYIBHuyUVMBkhGzobPjw==\012"}
=> "\"pgmQKWFl3ZqLWjMR6HISwjzbTSbF3qNj/xABLuR7sTRhG4hhVFDUBhrWLpHyXjOR0I9UB8zpzyOT\nJ0RDv0s9QcJgm5kx0+pPZFmIt/dfv5LH0UIYvEmODnbfqpzjV7uIgpoi+fdVJQaHwk1GF5W1F3hg\n2pWmc/aDz8saLG4j5I4U+cctEo7uUOOKn2xRszlytNIOylFQramG1UKC6TLFrkXjz24/MEfEPbaO\npHa2dzYbKN+2AOACVrspysnnAeG0W97EvaV9Q3OXdIY/9eElpLzrbgf+4weTG/qRTd7iSjautF0G\n9KMpzusxQxEI6hSrq+aYIBHuyUVMBkhGzobPjw==\n\""
But when I hit the server with that as a cookie
http localhost:9393 Cookie:cookie="\"pgmQKWFl3ZqLWjMR6HISwjzbTSbF3qNj/xABLuR7sTRhG4hhVFDUBhrWLpHyXjOR0I9UB8zpzyOT\nJ0RDv0s9QcJgm5kx0+pPZFmIt/dfv5LH0UIYvEmODnbfqpzjV7uIgpoi+fdVJQaHwk1GF5W1F3hg\n2pWmc/aDz8saLG4j5I4U+cctEo7uUOOKn2xRszlytNIOylFQramG1UKC6TLFrkXjz24/MEfEPbaO\npHa2dzYbKN+2AOACVrspysnnAeG0W97EvaV9Q3OXdIY/9eElpLzrbgf+4weTG/qRTd7iSjautF0G\n9KMpzusxQxEI6hSrq+aYIBHuyUVMBkhGzobPjw==\n\""
and try to retrieve the cookie from my app, it escapes the backslashes and turns + into spaces
encrypted_string = request.cookies['cookie']
"\"pgmQKWFl3ZqLWjMR6HISwjzbTSbF3qNj/xABLuR7sTRhG4hhVFDUBhrWLpHyXjOR0I9UB8zpzyOT\\nJ0RDv0s9QcJgm5kx0 pPZFmIt/dfv5LH0UIYvEmODnbfqpzjV7uIgpoi fdVJQaHwk1GF5W1F3hg\\n2pWmc/aDz8saLG4j5I4U cctEo7uUOOKn2xRszlytNIOylFQramG1UKC6TLFrkXjz24/MEfEPbaO\\npHa2dzYbKN 2AOACVrspysnnAeG0W97EvaV9Q3OXdIY/9eElpLzrbgf 4weTG/qRTd7iSjautF0G\\n9KMpzusxQxEI6hSrq aYIBHuyUVMBkhGzobPjw==\\n\""
string = key.private_decrypt(Base64.decode64(encrypted))
OpenSSL::PKey::RSAError: padding check failed
What am I missing? Thanks for your help.
For now, I'm just using gsub.
gsub("\\012","").gsub(" ","+")
I have tried below code. According to that it perform decoding on cookies you are passing and produce same result.
require ‘uri’
Say your cookie is:
c = “cookie=pgmQKWFl3ZqLWjMR6HISwjzbTSbF3qNj/xABLuR7sTRhG4hhVFDUBhrWLpHyXjOR0I9UB8zpzyOT\nJ0RDv0s9QcJgm5kx0+pPZFmIt/dfv5LH0UIYvEmODnbfqpzjV7uIgpoi+fdVJQaHwk1GF5W1F3hg\n2pWmc/aDz8saLG4j5I4U+cctEo7uUOOKn2xRszlytNIOylFQramG1UKC6TLFrkXjz24/MEfEPbaO\npHa2dzYbKN+2AOACVrspysnnAeG0W97EvaV9Q3OXdIY/9eElpLzrbgf+4weTG/qRTd7iSjautF0G\n9KMpzusxQxEI6hSrq+aYIBHuyUVMBkhGzobPjw==\n”
URI.decode_www_form(c).to_h
Output will be:
{"cookie"=>"pgmQKWFl3ZqLWjMR6HISwjzbTSbF3qNj/xABLuR7sTRhG4hhVFDUBhrWLpHyXjOR0I9UB8zpzyOT\nJ0RDv0s9QcJgm5kx0 pPZFmIt/dfv5LH0UIYvEmODnbfqpzjV7uIgpoi fdVJQaHwk1GF5W1F3hg\n2pWmc/aDz8saLG4j5I4U cctEo7uUOOKn2xRszlytNIOylFQramG1UKC6TLFrkXjz24/MEfEPbaO\npHa2dzYbKN 2AOACVrspysnnAeG0W97EvaV9Q3OXdIY/9eElpLzrbgf 4weTG/qRTd7iSjautF0G\n9KMpzusxQxEI6hSrq aYIBHuyUVMBkhGzobPjw==\n"}
See value of cookie key in hash.
pgmQKWFl3ZqLWjMR6HISwjzbTSbF3qNj/xABLuR7sTRhG4hhVFDUBhrWLpHyXjOR0I9UB8zpzyOT\nJ0RDv0s9QcJgm5kx0 pPZFmIt/dfv5LH0UIYvEmODnbfqpzjV7uIgpoi fdVJQaHwk1GF5W1F3hg\n2pWmc/aDz8saLG4j5I4U cctEo7uUOOKn2xRszlytNIOylFQramG1UKC6TLFrkXjz24/MEfEPbaO\npHa2dzYbKN 2AOACVrspysnnAeG0W97EvaV9Q3OXdIY/9eElpLzrbgf 4weTG/qRTd7iSjautF0G\n9KMpzusxQxEI6hSrq aYIBHuyUVMBkhGzobPjw==\n
You can see + is replaced with space.
Perform gsub(‘ ’, ‘+’) on cookie you received on server end.

MSXML2.ServerXMLHTTP and national characters

This question is related to this one: Character encoding Microsoft.XmlHttp in Vbscript, but differs in one thing, the national characters are in the domain name, not only arguments.
The task is: download a page from the given URL.
I already solved problem of passing UTF8 string into VBScript by reading it from UTF8 encoded file through ADO.
But now when I try opening it MSXML2.ServerXMLHTTP returns error: The URL is invalid.
Here is VBScript code:
Set objStream = CreateObject("ADODB.Stream")
objStream.CharSet = "utf-8"
objStream.Open
objStream.LoadFromFile("fileWithURL.txt")
url = objStream.ReadText()
objStream.Close
Set XMLHttpReq = CreateObject("MSXML2.ServerXMLHTTP")
XMLHttpReq.Open "GET", url, False
XMLHttpReq.send
WEBPAGE = XMLHttpReq.responseText
If you put something like hxxp://россия.рф/main/page5.html into the UTF8 encoded fileWithURL.txt the script will raise an error while working ok with hxxp://google.com.
The workaround is to use ascii representation of the domain name - but I yet haven't found PunnyCode encoder for vbscript (apart from Chillkat which is an overkill for my task).
Will appreciate your help on the main problem or workaround.
I've made an amazing journey in to depth of my hard drive and found a code writen by / for Jesper Høy. This was the source code of SimpleDNS Plus' IDN Conversion Tool at that time.
Archive.org page snapshot: http://www.simpledns.com/idn-convert.asp
Archive.org file snapshot: idn-convert-asp.zip
You can also copy the whole code from this gist.
Create a function to convert URLs.
Function DummyPuny(ByVal url)
Dim rSegments : rSegments = Split(url, "/")
If UBound(rSegments) > 1 Then
rSegments(2) = DomainPunyEncode(rSegments(2))
End If
DummyPuny = Join(rSegments, "/")
End Function
Then convert your url before making the request.
XMLHttpReq.Open "GET", DummyPuny(url), False

Unable to read a path with special characters in FSRef

With this code I am trying to get the path in const char *pathPtr from fsRefAEDesc. It gives the correct name and path if there are no special characters in the name of file which is there in fsRefAEDesc. Now if path has some special characters /Users/XYZ/.rtf I don't get a correct fsRef from AEGetDescData(). I believe it has some thing to do with Encoding and tried some them but could make it work.
FSRef fsRef;
//AEDesc fsRefAEDesc; //comes from some where.
status = AEGetDescData( &fsRefAEDesc, (void*)(&fsRef), sizeof(FSRef));
//OSErr result = FSMakeFSRefUnicode(&fsRef, 1024, (UniCharPtr)(&fsRef), kTextEncodingUnknown, &fileRef);
AEDisposeDesc( &fsRefAEDesc );
CFURLRef* gotURLRef = CFURLCreateFromFSRef(NULL, &fsRef);
CFStringRef macPath = CFURLCopyFileSystemPath(gotURLRef, kCFURLPOSIXPathStyle);
const char *pathPtr = CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding());
Is there is any way to read such paths?
At what point in your code does the problem occur? For instance, if you insert CFShow(macPath), do you see the right path in the debug log? If so, then you are not passing the right encoding to CFStringGetCStringPtr. Use UTF-8.
Also tried this for gotURLRef but I
got the same on my console i.e.
"/Users/Manish/Desktop/\u27a4\u00a9\u261a.png"
The Unicode escape sequence is what you get when going through CFURL calls. URL has very limited character range.
You can try FSRefMakePath. It will get you UTF8 encoded path from a FSRef.

Resources