BUG/MINOR: lua: Map.end are not reliable because "end" is a reserved keyword

This patch change the names prefixing it by a "_". So "end" becomes "_end".
The backward compatibility with names without the prefix "_" is assured.
In other way, another the keyword "end" can be used like this: Map['end'].

Thanks Robin H. Johnson for the bug repport

This should be backported in version 1.6 and 1.7
This commit is contained in:
Thierry FOURNIER 2017-01-28 08:33:08 +01:00 committed by Willy Tarreau
parent c0752565fe
commit 4dc7197338
2 changed files with 34 additions and 14 deletions

View File

@ -1863,7 +1863,7 @@ Map class
default = "usa" default = "usa"
-- Create and load map -- Create and load map
geo = Map.new("geo.map", Map.ip); geo = Map.new("geo.map", Map._ip);
-- Create new fetch that returns the user country -- Create new fetch that returns the user country
core.register_fetches("country", function(txn) core.register_fetches("country", function(txn)
@ -1888,60 +1888,76 @@ Map class
return loc; return loc;
end); end);
.. js:attribute:: Map.int .. js:attribute:: Map._int
See the HAProxy configuration.txt file, chapter "Using ACLs and fetching See the HAProxy configuration.txt file, chapter "Using ACLs and fetching
samples" ans subchapter "ACL basics" to understand this pattern matching samples" ans subchapter "ACL basics" to understand this pattern matching
method. method.
.. js:attribute:: Map.ip Note that :js:attr:`Map.int` is also available for compatibility.
.. js:attribute:: Map._ip
See the HAProxy configuration.txt file, chapter "Using ACLs and fetching See the HAProxy configuration.txt file, chapter "Using ACLs and fetching
samples" ans subchapter "ACL basics" to understand this pattern matching samples" ans subchapter "ACL basics" to understand this pattern matching
method. method.
.. js:attribute:: Map.str Note that :js:attr:`Map.ip` is also available for compatibility.
.. js:attribute:: Map._str
See the HAProxy configuration.txt file, chapter "Using ACLs and fetching See the HAProxy configuration.txt file, chapter "Using ACLs and fetching
samples" ans subchapter "ACL basics" to understand this pattern matching samples" ans subchapter "ACL basics" to understand this pattern matching
method. method.
.. js:attribute:: Map.beg Note that :js:attr:`Map.str` is also available for compatibility.
.. js:attribute:: Map._beg
See the HAProxy configuration.txt file, chapter "Using ACLs and fetching See the HAProxy configuration.txt file, chapter "Using ACLs and fetching
samples" ans subchapter "ACL basics" to understand this pattern matching samples" ans subchapter "ACL basics" to understand this pattern matching
method. method.
.. js:attribute:: Map.sub Note that :js:attr:`Map.beg` is also available for compatibility.
.. js:attribute:: Map._sub
See the HAProxy configuration.txt file, chapter "Using ACLs and fetching See the HAProxy configuration.txt file, chapter "Using ACLs and fetching
samples" ans subchapter "ACL basics" to understand this pattern matching samples" ans subchapter "ACL basics" to understand this pattern matching
method. method.
.. js:attribute:: Map.dir Note that :js:attr:`Map.sub` is also available for compatibility.
.. js:attribute:: Map._dir
See the HAProxy configuration.txt file, chapter "Using ACLs and fetching See the HAProxy configuration.txt file, chapter "Using ACLs and fetching
samples" ans subchapter "ACL basics" to understand this pattern matching samples" ans subchapter "ACL basics" to understand this pattern matching
method. method.
.. js:attribute:: Map.dom Note that :js:attr:`Map.dir` is also available for compatibility.
.. js:attribute:: Map._dom
See the HAProxy configuration.txt file, chapter "Using ACLs and fetching See the HAProxy configuration.txt file, chapter "Using ACLs and fetching
samples" ans subchapter "ACL basics" to understand this pattern matching samples" ans subchapter "ACL basics" to understand this pattern matching
method. method.
.. js:attribute:: Map.end Note that :js:attr:`Map.dom` is also available for compatibility.
.. js:attribute:: Map._end
See the HAProxy configuration.txt file, chapter "Using ACLs and fetching See the HAProxy configuration.txt file, chapter "Using ACLs and fetching
samples" ans subchapter "ACL basics" to understand this pattern matching samples" ans subchapter "ACL basics" to understand this pattern matching
method. method.
.. js:attribute:: Map.reg .. js:attribute:: Map._reg
See the HAProxy configuration.txt file, chapter "Using ACLs and fetching See the HAProxy configuration.txt file, chapter "Using ACLs and fetching
samples" ans subchapter "ACL basics" to understand this pattern matching samples" ans subchapter "ACL basics" to understand this pattern matching
method. method.
Note that :js:attr:`Map.reg` is also available for compatibility.
.. js:function:: Map.new(file, method) .. js:function:: Map.new(file, method)
@ -1951,10 +1967,10 @@ Map class
:param integer method: Is the map pattern matching method. See the attributes :param integer method: Is the map pattern matching method. See the attributes
of the Map class. of the Map class.
:returns: a class Map object. :returns: a class Map object.
:see: The Map attributes: :js:attr:`Map.int`, :js:attr:`Map.ip`, :see: The Map attributes: :js:attr:`Map._int`, :js:attr:`Map._ip`,
:js:attr:`Map.str`, :js:attr:`Map.beg`, :js:attr:`Map.sub`, :js:attr:`Map._str`, :js:attr:`Map._beg`, :js:attr:`Map._sub`,
:js:attr:`Map.dir`, :js:attr:`Map.dom`, :js:attr:`Map.end` and :js:attr:`Map._dir`, :js:attr:`Map._dom`, :js:attr:`Map._end` and
:js:attr:`Map.reg`. :js:attr:`Map._reg`.
.. js:function:: Map.lookup(map, str) .. js:function:: Map.lookup(map, str)

View File

@ -7258,6 +7258,10 @@ void hlua_init(void)
/* register pattern types. */ /* register pattern types. */
for (i=0; i<PAT_MATCH_NUM; i++) for (i=0; i<PAT_MATCH_NUM; i++)
hlua_class_const_int(gL.T, pat_match_names[i], i); hlua_class_const_int(gL.T, pat_match_names[i], i);
for (i=0; i<PAT_MATCH_NUM; i++) {
snprintf(trash.str, trash.size, "_%s", pat_match_names[i]);
hlua_class_const_int(gL.T, trash.str, i);
}
/* register constructor. */ /* register constructor. */
hlua_class_function(gL.T, "new", hlua_map_new); hlua_class_function(gL.T, "new", hlua_map_new);