Search query with & in title gives wrong results - node.js

I have been testing the musicbrainz API and I found a problem for me. When the title has an '&' in the name the query returns the wrong results.
For example: The title is 'auf & ab' and the query returns a title named 'auf, auf, auf'.
I sort of fixed this by replacing '&' with 'and' like this:
if (title.includes('&')){title = title.replace('&','and')}
This returns the correct results.
I am not sure if this is the way to solve this issue.
This is my query:
https://musicbrainz.org/ws/2/recording/?query=recording:auf%20&%20ab%20%26%26%20artist:montez&fmt=json&limit=5

I think you need to encode the "space" (with %20) and the "&" (with %26) chars, since they are used in url the & will be decoded as another new parameter in query string; try with this:
https://musicbrainz.org/ws/2/recording/?query=recording:auf%20%26%20ab&artist:montez&fmt=json&limit=5
In this way, your search "auf & ab" -> "auf%20%26%20ab"; you can achieve this result using the encodeURIComponent("auf & ab")
Edit: changed encodeURI -> encodeURIComponent

Related

How can I consider special character(&) as value in one of the query parameter

In GET API I have value as,
title=my&title
where the value from query param title returns only my and splits from & character.
Can anyone help me with how can I include & in my value?
Your query parameters should be URL-encoded in order to differenciate a separating & from a random character.
The solution is to encode the value before sending it through the request. You can do so by passing your value to encodeURIComponent(). You can then parse it the same way and decode it using decodeURIComponent(), e. g. :
encodeURIComponent('my&title') -> 'my%26title'
decodeURIComponent('my%26title') -> 'my&title'

nodejs how to replace ; with ',' to make an sql query

I have a query that looks like this:
INSERT INTO table VALUES ('47677;2019;2019;10T-1001-10010AS;A05;International;TieLineKoman-KosovoB;L_KOM-KOSB;2018;NULL;NULL;;NULL;Tieline;NULL;10XAL-KESH-----J;0;3')
that is produced by parsing a csv file.
The query is not in a valid form, I have to replace all semicolons with the string ',' (comma inside single quotes). What I want to get is:
('47677','2019','2019','10T-1001-10010AS','A05','International','TieLineKoman-KosovoB','L_KOM-KOSB','2018','NULL','NULL','','NULL','Tieline','NULL','10XAL-KESH-----J','0','3')
I have tried to do this in many different ways, but I end up with backshlashes added in my string. This is what I get:
"INSERT INTO AllocatedEICDetail VALUES ('47677\\',\\'2019\\',\\'2019\\',\\'10T-1001-10010AS\\',\\'A05\\',\\'International\\',\\'TieLineKoman-KosovoB\\',\\'L_KOM-KOSB\\',\\'2018\\',\\'NULL\\',\\'NULL\\',\\'\\',\\'NULL\\',\\'Tieline\\',\\'NULL\\',\\'10XAL-KESH-----J\\',\\'0\\',\\'3')"
Any ideas how to do this properly without having the backslashes added?
Thank you!
//the string you have
const string = '47677;2019;2019;10T-1001-10010AS;A05;International;TieLineKoman-KosovoB;L_KOM-KOSB;2018;NULL;NULL;;NULL;Tieline;NULL;10XAL-KESH-----J;0;3';
//the string you need:
const targetString = string.replace(/\;/g,',');
You specify a small regex between the forward slashes in replace which is a simple ';', give it a 'g' flag for global which will replace all instances, and in the second argument supply what you need it replaced with.

JScript Escape an ampersand in payload data for URL

I am attempting to launch a view using the following JS function:
$('#filterTop').click(function () {
var filterValue = $('#filterValueTop').val();
refreshView(`#Url.Action(Model.Action, Model.Controller)?pageSize=#Model.PageSize&pageNumber=#Model.PageNumber&sortDesc=#Model.SortDescending&filterType=#Model.FilterType&filterValue=${filterValue}&showAll=#Model.ShowAll` + `#Model.Payload`, '#Model.ResultView');
});
It worked great until I needed to append a static payload to the end of the URL. The relevant part is line 3 at the end:
&showAll=#Model.ShowAll` + `#Model.Payload`
I am assigning #Model.Payload a value of:
opts.Payload = "&batchID=" + batchID;
or "&batchID=25". The resulting URL is:
https://localhost:44303/Employee/Repaginate?pageSize=20&pageNumber=1&sortDesc=True&filterType=Name&filterValue=Jes&showAll=False&batchID=25
For some reason, it's translating the "&" to "&a.m.p;" (with no periods) which isn't a valid URL. I've tried various methods of escaping the character like using "%26", "/&", and several other garden varieties but alas, my attempts have been in vain. Any suggestions on what I am doing wrong?

Node parse raw string into query params

string:
?utm_campaign=My+Campaign+Name&utm_medium=email
I want to turn this into an object:
{
utm_campaign: "My Campaign Name",
utm_medium: "email"
}
I'm trying to find a way to accomplish this with the querystring module but can't seem to do it. Thank you!
Your problem is the &. It should be & otherwise it is treated as a regular character and not the special character separating query parameters.

Find index of a specific character in a string then parse the string

I have strings which looks like this [NAME LASTNAME/NAME.LAST#emailaddress/123456678]. What I want to do is parse strings which have the same format as shown above so I only get NAME LASTNAME. My psuedo idea is find the index of the first instance of /, then strip from index 1 to that index of / we found. I want this as a VBScript.
Your way should work. You can also Split() your string on / and just grab the first element of the resulting array:
Const SOME_STRING = "John Doe/John.Doe#example.com/12345678"
WScript.Echo Split(SOME_STRING, "/")(0)
Output:
John Doe
Edit, with respect to comments.
If your string contains the [, you can still Split(). Just use Mid() to grab the first element starting at character position 2:
Const SOME_STRING = "[John Doe/John.Doe#example.com/12345678]"
WScript.Echo Mid(Split(SOME_STRING, "/")(0), 2)
Your idea is good here, you should also need to grab index for "[".This will make script robust and flexible here.Below code will always return strings placed between first occurrence of "[" and "/".
var = "[John Doe/John.Doe#example.com/12345678]"
WScript.Echo Mid(var, (InStr(var,"[")+1),InStr(var,"/")-InStr(var,"[")-1)

Resources