puppetlabs/puppet — pull request #1263 by llange (2012-11-06 22:30:32+00:00)
Title: Bug #2437 : fix handling of nagios parameters with unescaped semicolon or pound sign

Current implementation of Nagios interface has somme issues dealing with parameters containing unescaped semicolons (;) or pound sign / hash symbol (#), as noted in bug #2437.
This patch tries to fix these issues, with the following rules - which come from Nagios documentation and source code :
- hash symbol (#) indicates a comment only when it is the first character on a line, or has spaces / tabs before.
- semicolon (;) indicates an inline comment anywhere on a line, except when the character immediately preceding is a backslash (\)

For homogeneity, I also took the following decisions regarding semicolons (;) :
- parameters read from the parser will have their semicolons unescaped - which means that if you have (\;) in a Nagios configuration file, it will come up as only one char (;) in the ruby object (an thus in Puppet nagios_* type)
- parameters from a ruby object or puppet type that contain a semicolon (;) will be escaped prior to be written in the configuration file.

The corresponding spec file has been augmented with test cases come either from the bug report, or artificially created to illustrate some cases.

A possible side effect of the patch is an enhancement of the parsing speed as the lexer was rewritten with StringScanner ; this seems to be visible with Ruby 1.9.x only.