-
Notifications
You must be signed in to change notification settings - Fork 15
Description
The toNode method has a bug.
# Public: Finds an Element Node using an XPath relative to the document root.
#
# If the document is served as application/xhtml+xml it will try and resolve
# any namespaces within the XPath.
#
# path - An XPath String to query.
#
# Examples
#
# node = toNode('/html/body/div/p[2]')
# if node
# # Do something with the node.
#
# Returns the Node if found otherwise null.
toNode = (path, root = document) ->
It will not find the node if the attribute selector has / or : in it. Example:
toNode("//p[@resource='http://purl.org/pearson/asset/adb19cb3a588ab58cbc0db272048aed6d60a29db5']") and toNode("//p[@resource='asset:adb4afbb2c91461765201bd8eb32f54aad1bb3800']") will not work. However toNode("//p[@resource='adb4afbb2c91461765201bd8eb32f54aad1bb3800']") works.
The problem is with the following code (line 161 in xpath.coffee):
path = (for segment in path.split '/'
if segment and segment.indexOf(':') == -1
segment.replace(/^([a-z]+)/, 'xhtml:$1')
else segment
).join('/')This will convert the //p[@resource='http://purl.org/pearson/asset/adb19cb3a588ab58cbc0db272048aed6d60a29db5'] into
//xhtml:p[@resource='http://xhtml:purl.org/xhtml:pearson/xhtml:asset/xhtml:adb19cb3a588ab58cbc0db272048aed6d60a29db5'] instead of converting to //xhtml:p[@resource='http://purl.org/pearson/asset/adb19cb3a588ab58cbc0db272048aed6d60a29db5']
I have never worked on coffee script and it took me a while to find the coffee script... by that time I made a code change to the generated code to fix the issue I am facing... Here is the screenshot of diff (which may not be useful):
http://content.screencast.com/users/harinair/folders/Jing/media/fac08329-05bf-4b51-8bba-cea25913dc15/00000064.png