JMSSecurityExtraBundle nested AND/OR expressions - symfony

I have this #PreAuthorize annotation:
#PreAuthorize("(hasRole('PERM_EDIT_ALL_CAMPAIGNS') or (has_role('PERM_EDIT_OWN_CAMPAIGNS') and isCampaignAccountManager(#id))) and (hasRole('PERM_EDIT_ALL_PUBLISHERS') or (has_role('PERM_EDIT_OWN_PUBLISHERS') and isAffiliateAccountManager(#paramFetcher.get('affiliate_id'))))")
I get the following error:
Expected primary expression, but got \u0022has_role\u0022 of type T_NONE at position
40 (0-based)
So the error looks like to appear after the bracket beginning here:
(has_role('PERM_EDIT_OWN_CAMPAIGNS') and isCampaignAccountManager(#id)))
Is there any way to add brackets in and/or expressions?
Thanks in advance

OMG!! sorry, I just realized after I wrote the question. I was using 'has_role' instead 'hasRole' :(

Related

Regular Expression to extract function arguments in R

I have a problem to extract function arguments in R.
x="theme(legend.position='bottom',
legend.margin=(t=0,r=0,b=0,l=0,unit='mm'),
legend.background=element_rect(fill='red',size=rel(1.5)),
panel.background=element_rect(fill='red'),
legend.position='bottom')"
What I want is:
[1]legend.position='bottom'
[2]legend.margin=(t=0,r=0,b=0,l=0,unit='mm')
[3]legend.background=element_rect(fill='red',size=rel(1.5))
[4]panel.background=element_rect(fill='red')
[5]legend.position='bottom'
I tried several regular expressions without success including followings:
strsplit(x,",(?![^()]*\\))",perl=TRUE)
Please help me!
I think the best answer here might be to not attempt to use a regex to parse your function call. As the name implies, regular expressions require regular language. Your function call is not regular, because it has nested parentheses. I currently see a max nested depth of two, but who knows if that could get deeper at some point.
I would recommend writing a simple parser instead. You can use a stack here, to keep track of parentheses. And you would only split a parameter off if all parentheses were closed, implying that you are not in the middle of a parameter, excepting possibly the very first one.
Arf, I'm really sorry but i have to go work, i will continue later but for now i just let my way to solve it partially : theme\(([a-z.]*=['a-z]*)|([a-z._]*=[a-z0-9=,'_.()]*)*\,\)?
It misses only the last part..
Here the regex101 page : https://regex101.com/r/BZpcW0/2
See you later.
Thank you for all your advice. I have parsed the sentences and get the arguments as list. Here is my solution.
x<-"theme(legend.margin=margin(t=0,r=0,b=0,l=0,unit='mm'),
legend.background=element_rect(fill='red',size=rel(1.5)),
panel.background=element_rect(fill='red'),
legend.position='bottom')"
extractArgs=function(x){
result<-tryCatch(eval(parse(text=x)),error=function(e) return("error"))
if("character" %in% class(result)){
args=character(0)
} else {
if(length(names(result)>0)){
pos=unlist(str_locate_all(x,names(result)))
pos=c(sort(pos[seq(1,length(pos),by=2)]),nchar(x)+1)
args=c()
for(i in 1:(length(pos)-1)){
args=c(args,substring(x,pos[i],lead(pos)[i]-2))
}
} else{
args=character(0)
}
}
args
}

How to get the expression used in an Assign activity

In the line below, "ThenActivity" is an Assign activity nested inside the Then part of an If activity. Im trying to get at the expression, but this snippet isnt working.
((Assign)ThenActivity).To.Expression.ToString();
This returns "1.13: CSharpReference"
When it should read R = 44.5M, which is the expression text, how do I get at it?
The statement should read something like this
((CSharpValue)(((Assign)ThenActivity).Value.Expression)).ExpressionText
Note: You need to get the assignment, then its expression, cast that as a CSharpValue, then finally you can get the ExpressionText.

Extracting value from HTML table and applying assertion

I am trying to extract a value which is in integer form i.e 60.
I have a code that is going through each row and each column and then using getText() method retrieve the value from column.
When applying testNG assertEqual,the value is not matched as the value found is "[60 ]" instead of "[60]".
Output of trace:
The Text is 60
Exception in thread "main" java.lang.AssertionError: expected [60] but found [60 ]
at org.testng.Assert.fail(Assert.java:94)
at org.testng.Assert.failNotEquals(Assert.java:494)
at org.testng.Assert.assertEquals(Assert.java:123)
at org.testng.Assert.assertEquals(Assert.java:165)
at rough.Test.main(Test.java:83)
Can someone help me finding how I can fix the assertion?
do you in fact have a trailing space in the table?
this is an issue that is good to find in testing
perhaps you should trim the result of getText()
Maybe because your code looks something like this<td>60 </td>
You are getting that extra space. You can try something like this.
String s = node.getText().trim();
assertEqual(s, "60");

This regex is not right

I am trying to use regex generators to create an expression, but I can't seem to get it right.
What I need to do is find the following type of string in a string:
community_n
For example, within the string which may be
community community_1 community_new_1 community_1_new
from that, I just want to extract community_1
I have tried /(community_\\d+)/, but that is clearly not right.
Try adding word boundries, so
/(\\bcommunity_\\d+\\b)/
Try using the regex (community_\d+).
Though I could be incorrect since I don't know which language you are using.
(For some reason I cannot add comments, I can only answer questions).

What does `{{{variable}}}` mean in handlebars?

What does triple curly braces mean in handlebars template syntax?
For example
{{{variable}}}
I cannot find any documentation.
Thanks
Because it was originally designed to generate HTML, Handlebars escapes values returned by a {{expression}}. If you don't want Handlebars to escape a value, use the "triple-stash", {{{.
Source: https://handlebarsjs.com/guide/#html-escaping
Found via: https://github.com/wycats/handlebars-site/issues/28

Resources