Added config option (IGNORE_XML_NAMESPACES) to make XML traversal using element local names only as a workaroud for XML namespace issues in some devices. Fixes #7.
This commit is contained in:
1 parent
dfb2e624d9
commit
de0774edeb
2 files changed
+12
No files matched your search
@@ -1,3 +1,4 @@
|
||||
config = require './config'
|
||||
libxmljs = require 'libxmljs'
|
||||
|
||||
SERVER_NAME = "GenieACS/#{require('../package.json').version}"
|
||||
@@ -41,6 +42,16 @@ NAMESPACES = {
|
||||
}
|
||||
|
||||
|
||||
# Workaround for devices that don't use correct namespace declarations or prefixes
|
||||
if config.IGNORE_XML_NAMESPACES
|
||||
libxmljs.Element.prototype.__find = libxmljs.Element.prototype.find
|
||||
libxmljs.Element.prototype.find = (xpath, namespaces) ->
|
||||
# Modify xpath queries to work regardless of element's namespace
|
||||
p = xpath.replace(/([^\/:]+:)?([^\/]+)(\/|$)/g, '$2$3') \
|
||||
.replace(/([a-zA-Z0-9_-]+)([^\/]*)(\/|$)/g, "*[local-name()='$1']$2$3")
|
||||
libxmljs.Element.prototype.__find.call(this, p, namespaces)
|
||||
|
||||
|
||||
# Separation by comma is important as some devices don't comform to standard
|
||||
COOKIE_REGEX = /\s*([a-zA-Z0-9\-_]+?)\s*=\s*"?([a-zA-Z0-9\-_]*?)"?\s*(,|;|$)/g
|
||||
|
||||
|
||||
Reference in new issue
Block a user