MimeUtility.DecodeText() returns ? characters - mime

"=?utf-8?B?MDJf5rW35aSW5oug54K5X0ZZMTXjgrfjgrnjg4bjg6DlgZzmraLlpInm?= =?utf-8?B?m7TkvZzmpa3kuojlrppfMjAxNTA1MDdWMS5wcHR4?="
I am trying to decode the above string using MimeUtility.DecodeText method. I get the resultant string as follows:
02_海外拠点_FY15システム停止変���作業予定_20150507V1.pptx
I am expecting the string to be :
02_海外拠点_FY15システム停止変更作業予定_20150507V1.pptx

Related

URI within endpoint

I have a URI string inside the request that I am supposed to make. How to extract it and write a proper controller.
markerURI = marker://markerType/markerValue
Request:
POST /books/123/markers/marker://big/yellow
I have written below rest controller for the above request:
#PostMapping("/books/{id}/markers/{markerURI:^marker.*}")
public void assignMarker(
#PathVariable("id") String id,
#PathVariable("markerURI") String markerURI
)
but i'm not able to get markerURI=marker://big/yellow inside markerURI variable. The request show 404 Not found error. Is there any way to do this. It's a requirement so can't do any hacks.
Edit:
markerURI can contain attributes like marker://markerType/markerValue?attr1=val1&attr2=val2
As per https://docs.spring.io/spring-framework/docs/current/reference/html/web.html#mvc-ann-requestmapping-uri-templates
You can have your url pattern in below pattern
"/resources/ima?e.png" - match one character in a path segment
"/resources/*.png" - match zero or more characters in a path segment
"/resources/**" - match multiple path segments
"/projects/{project}/versions" - match a path segment and capture it as a variable
"/projects/{project:[a-z]+}/versions" - match and capture a variable with a regex
but your url pattern is defined as a url inside a url, for that I suggest you to use below method and concatenate your result after fetching the values from uri as pathvariable.
#PostMapping("/books/{id}/markers/{marker:[a-z]+}://{markerType:[a-z]+}/{markerValue:[a-z]+}")
public void assignMarker(#PathVariable("id") String id,#PathVariable("marker") String marker,
#PathVariable("markerType") String markerType,
#PathVariable("markerValue") String markerValue) {
String markerUri = "/"+marker+"://"+markerType+"/"+markerValue;
System.out.println(markerUri);
}

How to make Get Request with Request param in Postman

I have created an endpoint that accepts a string in its request param
#GetMapping(value = "/validate")
private void validateExpression(#RequestParam(value = "expression") String expression) {
System.out.println(expression);
// code to validate the input string
}
While sending the request from postman as
https://localhost:8443/validate?expression=Y07607=Curr_month:Y07606/Curr_month:Y07608
// lets say this is a valid input
console displays as
Y07607=Curr_month:Y07606/Curr_month:Y07608 Valid
But when i send
https://localhost:8443/validate?expression=Y07607=Curr_month:Y07606+Curr_month:Y07608
//which is also an valid input
console displays as
Y07607=Curr_month:Y07606 Curr_month:Y07608 Invalid
I am not understanding why "+" is not accepted as parameter.
"+" just vanishes till it reaches the api! Why?
I suggest to add this regular expression to your code to handle '+' char :
#GetMapping(value = "/validate")
private void validateExpression(#RequestParam(value = "expression:.+") String expression) {
System.out.println(expression);
// code to validate the input string
}
I didn't find any solution but the reason is because + is a special character in a URL escape for spaces. Thats why it is replacing + with a " " i.e. a space.
So apparently I have to encode it from my front-end
Its wise to encode special characters in a URL. Characters like \ or :, etc.
For + the format or value is %2. You can read more about URL encoding here. This is actually the preferred method because these special characters can sometimes cause unintended events to occur, like / or = which can mean something else in the URL.
And you need not worry about manually decoding it in the backend or server because it is automatically decoded, in most cases and frameworks. In your case, I assume you are using Spring Boot, so you don't need to worry about decoding.

Find the value stored in this string

I am having a string containing the following data:
str="AAAEsw==\xfc\x01\xde\x00\x1b\xa41165\xdc\x00\x15\xc0\xc0\xa12\xc0\x01\x00\xef\xa820180518\xa41681&\x00\x0b\x82423\xa42450&\x00\x1c1K\x00\bL\x00#04L\x00\x0f&\x00\x05q131\xa3496K\x00?\xa279L\x00\x04q224\xa3497&\x00?\xa310\xbf\x00\x05\xf5\x16705\xa3599\xdc\x00\x15\xb30.10482180293501049\xa31.0\xa210\x8b\x00\x00\x10\x00\x04\r\x00%\xa11\xb5\x002\xa341\x8f\x00/\xa16\x8e\x00\x04\x81529\xa41938\x8f\x00/\xa14&\x00\x05R18\xa371\xb4\x00$\xa21u\x00\x06\x02\x00\x02q\x00`715\xa371\xb3\x00F\xc0\xc0\xa17\x1e\x00\x03\x02\x00\x02\x97\x01A424\xa2\xd7\x00P\xb40.01\xa9\x01\xf4\x05995475113122\xa40.36\xa263\xcc\x00\x06\x02\x00\x02>\x00r602\xa4117\xfb\x01/\xa21\xb0\x00\x05s705\xa4120\xfc\x00\x0fc\x01\x05\x01\"\x02 02\xb1\x00\x01\x8d\x00\xff\b7584994138335287\xa30.3\xa237\x8c\x00\x05\xf5\x16713\xa3122\xdc\x00\x15\xb20.0995558845299778\xa42.69\xa250S\x01`\xa41.34\xa1\xe1\x00C66\xa11\x0e\x00\x00\x17\x00#14\xb0\x01\x01\xdc\x00 24\x8f\x00O\xc0\xc0\xa26\xdc\x00\x05\x00\xb2\x012233\x8d\x01\x0e\x9c\x00\x04\xb2\x02029\xa1\x9b\x00\xf0\x0b\xb30.07170966331438565\xa41.64\xa2\x8e\x00\x03_\x01\x01\x11\x00\x04\x0e\x00\"\xa13k\x01Q529\xa34\xdf\x00O\xc0\xc0\xa25D\x01\x05b608\xa348?\x023\xa215Q\x00\x06\x02\x00\x02L\x00\x00\x1a\x02#88\x8f\x01\x0f?\x02\x05c516\xa424\xdc\x01\x04\x8e\x00\a\x02\x00\x02K\x00c507\xa368%\x01\x1f2\xd7\x02\x05\x01\x97\x00\x140&\x00\x0f\x8c\x02\x05d601\xa419M\x00\x1f1'\x00\x05P203\xa22\xfc\x03\xf0\n\xb50.0049186530457813096\xa40.\n\x02.19\x8d\x01\x90\xa820180713"
how to get the actual value?

comparing a url containing utf-8 encoded string with a string

I have a url
"/complete/search?nolabels=t&client=chrome&ds=yt&q=%D1%8D%D1%82%D0%BE%20%D1%80%D1%8D%D0%BF%20%D0%B8%D0%BC%D0%BF%D1%80&hl=ru"
and a list of key words. I need to determine if the url contains any of those words.
I checked this string %D1%8D%D1%82%D0%BE%20%D1%80%D1%8D%D0%BF%20%D0%B8%D0%BC%D0%BF%D1%80
using
utf-8 encoder
thought I had to change % to \x for it to work.
I try using regular expressions for this
select "/complete/search?nolabels=t&client=chrome&ds=yt&q=%D1%8D%D1%82%D0%BE%20%D1%80%D1%8D%D0%BF%20%D0%B8%D0%BC%D0%BF%D1%80&hl=ru" rlike encode("это рэп импр", "UTF-8");
but it doesn't accept a binary as an argument and base64(encode("это рэп импр", "UTF-8")) doesn't return the type of string I need.
My question is, how do I turn this это рэп импр into this %D1%8D%D1%82%D0%BE%20%D1%80%D1%8D%D0%BF%20%D0%B8%D0%BC%D0%BF%D1%80?
Found this
SELECT reflect("java.net.URLDecoder", "decode", "/complete/search?nolabels=t&client=chrome&ds=yt&q=%D1%8D%D1%82%D0%BE%20%D1%80%D1%8D%D0%BF%20%D0%B8%D0%BC%D0%BF%D1%80&hl=ru", "UTF-8");

'StartsWith' not working in Linq-To-EF

I have implemented a Linq-to-EF expression using the sting comparison 'StartsWith', but it is behaving like the string comparison 'Contains'... my code is:
string ubi = '12';
return (from u in _dataContext.Notice
where u.UB.StartsWith(ubi)
select new AutoCompleteData { Value = u.UB }).Distinct().Take(50);
I would expect the data returned to be only values that start with '12'...but it returns values like '44412' and '312' as well as '1245' and '1299'.
Am I missing something ?

Resources