There are 2 spaces before every key in "headers" : "headers" : " \r\n\s\sOrigin: http://site.com\r\n\s\sX-dev: Device1\r\n\s\sConnection: Keep-Alive\r\n", and kv.trim_key removes only one of them, while expected all be removed if i got it.
As a result all generated fields start with space symbol, e.g "\sOrigin" : "http://site.com"
Questions are:
Was kv.trim_key behavior changed ?
How is it possible to trim all leading/trailing symbols in kv plugin (without additional plugins usage) ?
This happens because both trim_key and trim_value features are using regular expression patters:
Regexp.new("^[#{@trim_key}]|[#{@trim_key}]$")
It removes the first symbol of the group from the beginning of the string and the last symbol of the string if it matches too. Most likely it's not what you want because "trimming" means removing all matching symbols from the start and from the end of the string. So, the correct expressing would be:
Regexp.new("^[#{@trim_key}]+|[#{@trim_key}]+$")
This behavior have changed from the version 1 of this plugin where the expression was like this:
Regexp.new("[#{@trim_key}]")
It was matching all symbols in the group anywhere is the string. It's wrong too because only symbols from the beginning and from the end should be removed, not from the middle of the string surrounded by other symbols.
Unit tests in the plugin only check for the single space examples so this problem was not detected.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.