Brakeman error parse error on value ')' as a result of updated syntax - ruby-on-rails

I have recently installed brakeman and ran the gem on my system. One error it is picking up is in relation to what I believe is a parenthesis.
The line of code it is picking an error up on is:
%p=link_to("Click here", url_for(only_path: false, host: ConfigSetting.get("FORGET_PASSWORD_HOST_PREFIX","localhost"), account_new_passwd_reset_path(key: #guid)))
I have recently updated syntax which required an extra parenthesis after the 'account_new_passwd_path'. I believe this is the issue but I cannot understand why.
The outdated code I had was:
%p=link_to("Click here", url_for(:only_path=>false, :host=>ConfigSetting.get("FORGET_PASSWORD_HOST_PREFIX","localhost"), :controller=>:account, :action=>:new_passwd_reset, :key=>#guid))
As you can see in terms of the routing it is the biggest change around the key #guid area.
Any ideas?
The error I am receiving is 'Error: app/views/passwd_reset_mailer/password_reset.haml:3 :: parse error on value ")" (tRPAREN) Could not parse app/views/passwd_reset_mailer/password_reset.haml'

The problem is the order of arguments. Keyword arguments need to be at the end of the argument list. But then there is another issue that using a url helper together with url_for doesn't really makes sense.
Just change:
%p=link_to(
"Click here",
url_for(
only_path: false,
host: ConfigSetting.get("FORGET_PASSWORD_HOST_PREFIX","localhost"),
account_new_passwd_reset_path(key: #guid)
)
)
to
%p=link_to(
"Click here",
account_new_passwd_reset_url(
host: ConfigSetting.get("FORGET_PASSWORD_HOST_PREFIX","localhost"),
key: #guid
)
)
Please note the _url instead of the _path suffix, which test Rails to build a full URL including the hostname.

Related

How to fix an 'Invalid tag name' in WSDL request using Zeep?

When trying to access a WSDL service, I get the following error:
ValueError: Invalid tag name 'Foo\\Bar\\Baz\\Etc\\V3Port'
The port which is provided through the WSDL-link actually has single backslashes: 'Foo\Bar\Baz\Etc\V3Port'
The ValueError gets raised when zeep calls the apihelpers.pxi method in the lxml library.
Any idea how I can fix this?
(BTW: the script worked fine when I used it 2 months ago. The WSDL-link hasn't changed)
I have found a solution
Before, it was sufficient to do:
from zeep import Client
Now, apparently, I need to explicitly add:
from lxml import etree
Everything works as before now.
Zeep does not like like "/" in values also. It gives invalid tag name error any time it finds any character in value that it does not like. For all such errors, you need to modify as_qname function in utils.py located in root folder of zeep library.
In my case, it was complaining for "/" in value, which is a valid value. I had to add below line to as_qname function.
value = value.replace("/", "-")
Below are first few lines of as_qname after modification
def as_qname(value: str, nsmap, target_namespace=None) -> etree.QName:
"""Convert the given value to a QName"""
value = value.strip() # some xsd's contain leading/trailing spaces
value = value.replace("/", "-") # Added by me.
if ":" in value:
prefix, local = value.split(":")

ROBLOX Lua Error in script: '=' expected near '<eof>'

Hello I am writing a scipt on ROBLOX and I have encountered a problem.
function showVictoryMessage(playerName)
local message = Instance.new("Message")
message.Text = playerName .." has won!"
message.Parent = game.Workspace
wait (2)
message.Destroy()
end
Upon running this function, or more specifically the "message.Destroy" command, I get the error: Error in script: '=' expected near '< eof >'
I have never seen this error before, and the ROBLOX wiki page on Lua errors doesn't mention it.
I would very much appreciate help in this, because I don't personally know anyone who has coded in Lua.
Looks like a syntax error. message.Destroy() should be message:Destroy() according to this Roblox wiki page http://wiki.roblox.com/index.php?title=API:Class/Instance/Destroy
Also see the section Explosions, Messages, and More at URL http://wiki.roblox.com/index.php?title=Basic_Scripting which provides similar syntax using the colon (:) operator.
See also Difference between . and : in Lua and explanation of "possible side-effects of calculations/access are calculated only once" with colon notation.
Instead of message.Destroy() it should be message:Destroy()
Remember that '.' are used directory-wise and ":' are used for inbuilt functions.
WOOOOOOOO! It was a syntax error. The correct command is message:Destroy. Cause why would object.Destroy work and message.Destroy not?

Why is my JSON.parse failing? Ruby on Rails

I'm trying to load images from Flickr's API into a Ruby on Rails app, but I'm getting "Unexpected Token" on my JSON.parse() line.
I found another response here where the returned JSON had it's double quotes escaped out, and the solution was to add the .gsub thing to the end, but I'm still getting an error.
Anyone know what the problem is?
def add
#jsonresults = open("http://api.flickr.com/services/rest/?method=flickr.interestingness.getList&api_key=bb398c11934abb6d51bdd720020f6a4a&per_page=1&page=1&format=json&nojsoncallback=1").read
#images = JSON.parse(#jsonresults.to_json.gsub('\"', '"'))
end
The error:
JSON::ParserError in ImagesController#add
757: unexpected token at '"{"photos":{"page":1, "pages":500, "perpage":1, "total":500, "photo":[{"id":"8234011021", "owner":"24066605#N07", "secret":"b4c05df8c5", "server":"8341", "farm":9, "title":"Crescent Lake", "ispublic":1, "isfriend":0, "isfamily":0}]}, "stat":"ok"}"'
The json returned by the call looks fine. Change your parsing to this:
#images = JSON.parse(#jsonresults)
That is not valid JSON. The outer set of double-quotes do not belong. This is the valid version:
'{"photos":{"page":1, "pages":500, "perpage":1, "total":500, "photo":[{"id":"8234011021", "owner":"24066605#N07", "secret":"b4c05df8c5", "server":"8341", "farm":9, "title":"Crescent Lake", "ispublic":1, "isfriend":0, "isfamily":0}]}, "stat":"ok"}'

Double closure fails in GSP

In a GSP file I write something like this:
${tgs.singleGameSheets.find{it.matchnumber==1}.awayPlayer.fullname()}
But I receive the following error:
org.codehaus.groovy.control.MultipleCompilationErrorsException:
startup failed:
C__STS_Projekte_TischtennisManager_grails_app_views_league__showGameSheet_gsp:
49:expecting '}', found ')' # line 49, column 134.
heets.find{it.matchnumber==1 })
The problem seems to be the double closure as I've found a bug report here.
Unfortunately the solution from the bugreport with the %= and % at the beginning and the end of the tag is not working for me.
Are there any other workarounds or solutions for this double closure problem?
I'm using Grails 1.3.7.
You may have to split this up in to two lines.
Try assigning the find results to a separate var first
<% def r = tgs.singleGameSheets.find{it.matchnumber==1} %>
${r*.awayPlayer.fullname()}
I would recommend firstly to do this sort of data processing in the controller and hand data that is as well prepared as possible down to the view.
If you are unable to do that, I would recommend trying to use parenthesis:
${tgs.singleGameSheets.find{it.matchnumber==1}.awayPlayer.fullname()}
becomes
${(tgs.singleGameSheets.find{it.matchnumber==1}.awayPlayer.fullname())}
That has worked for me on past occasions where I had to do ${(someCollection.findAll { someClause })}

symfony sfDoctrineRouteCollection routing throws 404 error "Empty module and/or action after parsing the URL..."

I have the following routing configuration:
entry:
class: sfDoctrineRouteCollection
options:
model: ProjectEntry
module: entry
prefix_path: /entry
column: slug
with_show: false
model_methods:
{ object: getEntryBySlug }
requirements:
slug: \w+
which, among others, gives me the following output with the symfony app:routes :
entry_edit GET /entry/:slug/edit.:sf_format
at lib/model/doctrine/ProjectEntryTable.class.php I have the following method:
public static function getEntryBySlug($parameters)
{
return Doctrine_Core::getTable('ProjectEntry')->findOneBySlug($parameters['slug']);
}
However, when I enter an URL such as:
frontend_dev.php/entry/my-slug/edit
I get the following error:
404 | Not Found | sfError404Exception
Empty module and/or action after parsing the URL "/entry/my-slug/edit" (/).
(assume that my-slug is a valid slug for some record at ProjectEntry table)
I haven't found the cause of this error, what may I be doing wrong?
As far as I can tell, the problem is at the routing configuration (but where?!), because even if I try to debug something at my executeEdit action, I notice that I don't even get there. (If it's needed, I can post more code/output here...)
Any ideas deeply appreciated...
Ok, got it!
I just had to remove the requirement for the slug and that was it.
The thing is that sfDoctrineRouteCollection (and maybe other sfObjectRouteCollections? anyone knows?) generates its routes, like the edit one, as:
prefix/column/edit
so if column has a \w+ requirement, it is basically saying that anything after the prefix is part of the column, including the '/edit' part. Removing the requirement loads the default one ([^ / \ \ .]+), which as far as I understand of regexes says that the next '/' is the limit...
sorry for such a newbie question, but it is now solved...

Resources