Error loading Partial View script (file: ~/Views/MacroPartials/ezSearch.cshtml) - umbraco

I am having some issue with ezSearch (Umbraco) and it is very similar to this one
http://our.umbraco.org/projects/website-utilities/ezsearch/bugs-feedback-suggestions/48460-Search-error-when-searching-for-test-keyword?p=0#comment176864
Here is the screenshot of error
http://our.umbraco.org/media/upload/e08b702e-b738-42a4-81d8-382a4400b96a/error.jpg
Can anyone hep me with this please?
Thank you,
Adi

I'm using ezSearch, and from reading the ezSearch.cshtml this looks like a bug if the query passed to the macro is " ". That is to say, if the search is empty, it works ok, but if the search is an actual quoted space then the line in the cshtml: (line 60 in my version)
// Check the search term isn't empty
if(!string.IsNullOrWhiteSpace(model.SearchTerm))
{
// Tokenize the search term
model.SearchTerms = Tokenize(model.SearchTerm);
...
etc.
...
}
ends up with a bad set of tokens in model.SearchTerms.
it's a bit of a hack, but i think putting this before that if statement will help.
model.SearchTerm = model.SearchTerm.Replace("\"","").Replace(" ","").Replace("'","");
..hope that helps.
'ingie.

Related

string.len() always returns the error "unexpected symbol"

function Main(Inhalt)
print(string.len(Inhalt))
end
Main(Bla)
This is just a example, I run in multiple problems like: "input:3: bad argument #1 to 'len' (string expected, got nil)" (Like here), or anything else with unexpected.
I'm kinda new to this, so please explain it to me from ground up I'm trying to figure out for a pretty long time. I already tried to convert this to a string with tostring(), but yes I'm missing something. Thanks for your help.
In this case Bla either needs to be a string which you can fix by putting quotes around it
function Main(Inhalt)
print(string.len(Inhalt))
end
Main("Bla")
or needs to be a variable that contains a string
Bla="test string"
function Main(Inhalt)
print(string.len(Inhalt))
end
Main(Bla)
Not a lua expert but it seems like you're trying to get the length of the string value Bla. The way you've written it right now does not indicate Bla is of string type. If you change it to the following, this should work.
function Main(Inhalt)
print(string.len(Inhalt))
end
Main("Bla")
Try this:
string1 = "Bla"
Main(string1)
In your code snippet Bla is not defined. Strings are surrounded by "".

lua sub string replace 2 pattern

due to using nginx lua (kong gateway)
would like to replace
from
{"body":"\r\n \"username\": \"sampleUser\",\r\n \"password\": \"samplePassword\",\r\n"}
to
{"body":"\r\n \"username\": \"sampleUser\",\r\n \"password\": \"***REDACTED***\",\r\n"}
from
username=sampleUser&password=samplePassword
to
username=sampleUser&password=***REDACTED***
from
"password" : "krghfkghkfghf"
to
"password" : "***REDACTED***"
i did try on sample https://stackoverflow.com/a/16638937/712063
local function replacePass(configstr, newpass)
return configstr:gsub("(%[\"password\"%]%s*=%s*)%b\"\"", "%1\"" .. newpass .. "\"")
end
it does not work, any recommended reference ?
maybe something like this:
local t = {
[[{"body":"\r\n \"username\": \"sampleUser\",\r\n \"password\": \"samplePassword\",\r\n"} ]],
[[username=sampleUser&password=samplePassword]],
[["password" : "krghfkghkfghf"]]
}
local newpass ="***REDACTED***"
for k,example in pairs(t) do
res = example:gsub('(password[\\" :]+)(.-)([\\"]+)',"%1"..newpass.."%3")
res = res:gsub("(password=).+","%1"..newpass)
print(res)
end
out:
{"body":"\r\n \"username\": \"sampleUser\",\r\n \"password\": \"***REDACTED***\",\r\n"}
username=sampleUser&password=***REDACTED***
"password" : "***REDACTED***"
There's several things wrong with that at first sight.
1. You only check for =
In your test data you seem to have cases with key = value as well as key : value but your pattern only checks for =; replace that with [=:] for a simple fix.
2. You can't balance quotation marks
I don't know how you expect this to work, but [[%b""]] just finds the shortest possible string between two " characters, just as [[".-"]] would. If that's your intention, then there's nothing wrong with writing it using %b though.
3. Just don't
As I don't know the context, I can't say if this really is a bad idea or not, but it does seem like a very brittle solution. If this is an option, I would recommend considering the alternative and going with something more robust.
As for what a better alternative could look like, I can't say without knowledge of your requirements. Maybe normalizing the data into a Lua table and replacing the password key in a uniform way? This would make sure that the data is either sanitized, or errors during parsing.
Beyond that, it would help if you told us how it doesn't work. It's easy to miss bugs when reading someone elses code, but knowing how the code misbehaves can help a lot with actually spotting the problem.
EDIT:
4. You didn't even remove the brackets
You didn't even remove the [] from that other stack overflow answer. Obviously that doesn't work without any modifications.

regular expression for removing empty lines produces wrong results

Can someone help me solve the problem I'm having with a regular expression? I have a file containing the following code:
I'm using a visit to find matches and replace them so that I can remove the empty lines. The result is, however, not what I'm expecting. The code is as follows:
str content = readFile(location);
// Remove empty lines
content = visit (content) {
case /^[ \t\f\v]*?$(?:\r?\n)*/sm => ""
}
This regular expression also removes non empty lines resulting in an output equal to:
Can someone explain what I'm doing wrong with the regular expression as well as the one shown below? I can't seem to figure out why it's not working.
str content = readFile(location);
// Remove empty lines
content = visit (content) {
case /^\s+^/m => ""
}
Kind regards,
Bob
I think the big issue here is that in the context of visit, the ^ anchor does not mean what you think it does. See this example:
rascal>visit ("aaa") { case /^a/ : println("yes!"); }
yes!
yes!
yes!
visit matches the regex at every postfix of the string, so the ^ is relative for every postfix.
first it starts at "aaa", then at "aa" and then at "a".
In your example visit, what will happen is that empty postfixes of lines will also match your regex, and substitute those by empty strings. I think an additional effect is that the carriage return is not eaten up eagerly.
To fix this, simply not use a visit but a for loop or while, with a := match as the condition.

Getting run-time error for 'rotate the doubly linked list'

I am posting this question because i am getting run-time error for any linked list problem that i code. There must be a generic mistake that I must be doing. Please help me figure out what's that mistake
This is just one of those problems:
https://practice.geeksforgeeks.org/problems/rotate-doubly-linked-list-by-p-nodes/1
Here is my solution:(I was only supposed to complete the function)
struct node*update(struct node* start,int p)
{
//Add your code here
node *last=start,*nxt,*i=start;
int n=1;;
while(last!=NULL){
last=last->next;
n+=1;
}
cout<<last->data<<"\n";
p=p%n;
for(int i=0;i<p;i++){
nxt=start->next;
last->next=start;
start->next=NULL;
start->prev=last;
nxt->prev=NULL;
last=last->next;
start=nxt;
}
return start;
}
Please let me know what is wrong with this code.
Thank you in advance
So , you're trying your hands on linked-lists ,that's great .
Linked list is like a game , a 'game of pointers' . You seems to very good in the 'game of logics' while you lack just a few things in ' pointers game'.
Going through your mentioned statement- " i am getting run-time error for any linked list problem that i code.", I would suggest you to learn how to debug your code and how self testing of code is done .
Coming back to your code , you are traversing the whole list to get access of the last node . To achieve that goal - you have used while loop . But look what conditional statement you've used in that , and what you'll be left with after execution of while loop .
node *last=start,*nxt,*i=start;
int n=1;;
while(last!=NULL){
last=last->next;
n+=1;
}
At first try to check you code for a linked list of size 2 or 3 only.
Isn't your code giving the value of n as [size(of linked-list) +1] and you are left with last pointer pointing to NULL. So how will you be able to get last->data when last is NULL.
Just a simple mishandling of pointers . Otherwise the logic of your later code part is fine .
Modification needed
Last node is the one , whose next is pointing to NULL . So run your loop till that node only .
int n=1;;
while(last->next!=NULL){ //last->next instead of last
last=last->next;
n+=1;
}
Hope this will help .
Keep asking , keep growing :)

php str_replace produces strange results

I am trying to replace some characters in a text block. All of the replacements are working except the one at the beginning of the string variable.
The text block contains:
[FIRST_NAME] [LAST_NAME], This message is to inform you that...
The variables are defined as:
$fname = "John";
$lname = "Doe";
$messagebody = str_replace('[FIRST_NAME]',$fname,$messagebody);
$messagebody = str_replace('[LAST_NAME]',$lname,$messagebody);
The result I get is:
[FIRST_NAME] Doe, This message is to inform you that...
Regardless of which tag I put first or how the syntax is {TAG} $$TAG or [TAG], the first one never gets replaced.
Can anyone tell me why and how to fix this?
Thanks
Until someone can provide me with an explanation for why this is happening, the workaround is to put a string in front and then remove it afterward:
$messagebody = 'START:'.$messagebody;
do what you need to do
$messagebody = substr($messagebody,6);
I believe it must have something to do with the fact that a string starts at position 0 and that maybe the str_replace function starts to look at position 1.

Resources