(#15398) fix typo in Scope#number? float detection regex

This allowed incorrect numbers (like 2:.34) to be recognized as
floats (with an incorrect value).

Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
zaml: statically determine the to_ascii8bit implementation.

Instead of asking every single string the same question, "do you respond to
`encoding`", we can just figure that out once and choose an implementation
based on the result - since it is a static test on the same class every time.

This saves ~ 0.1 second of runtime, which is small but cheap.

Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>
zaml: rework strings for correctness and speed

This changes the implementation of string output in the ZAML encoder.  On my
test that delivers around a fifty percent reduction in output time, from 4.11
to 1.89 seconds on my test of ~ 35,000 output strings.

It also adds a bunch of tests to validate the correctness of binary output
handling, and some test inputs derived from various security related UTF-8
encoding problems to validate that (sadly) we pass them through as
binary data.

Optimally we would treat binary and text input as distinct in the parser and
compiler of Puppet, then only allow legal UTF-8 in strings - but that is not
the world in which we live.

It finally fixes a bug in the binary output along the way - which, thankfully,
nobody actually seems to have run into since I introduced it in ea0dd1483fc2.

Because the Ruby BASE64 encoder will split lines at the 60 character mark, a
long binary input would end up with embedded newlines in places that were not
legal for YAML.

Instead of just emitting that, we run through the string encoder over the
transformed data, which leads to a solid output format that works entirely
as expected.

Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>
zaml: add whitespace for readability.

The ZAML code has very little whitespace, leading to a difficult to read set
of code.  This just adds a little whitespace, with no behaviour change, to
improve that before I start hacking directly on that code.

Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>
zaml: avoid calling emit when we don't have anything to output

The `nl` method allowed an additional string to be output after the newline;
this is seldom used, and the default implementation resulted in emitting an
empty string.

We can just skip that, for a minor win in function call count.

Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>
zaml: don't use backreferences on strings

While the YAML spec requires that we emit a backreference if the same string
object occurs twice in our content, it also costs a lot.  About two seconds of
time encoding the output, in my testing, out of a total of three.

Everything we do internally with YAML doesn't actually *depend* on the ability
to serialize an object graph that treats String objects as duplicated.

This is reinforced by every object that can serialize to PSON - since
it *can't* have a back-reference, you automatically get string duplication
there.

That means that we can just cut those few seconds out of the code without any
particular cost or suffering, and shave *way* more time off a run than almost
anything else we can do to our YAML output code.

Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>
Merge pull request #943 from joshcooper/maint/2.7.x/openrc-spec

(Maint) Don't assume paths are absolute
Merge pull request #935 from daniel-pittman/perf/3.x/zaml-performance

ZAML/YAML performance and correctness fixes
Implement `Fixnum#ord` for Ruby 1.8.5

This is a compatibility method for addressing characters introduced in 1.8.7;
we also need the same compatibility back to 1.8.5, so we monkey-patch it in
when it isn't already there.

Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>
Merge pull request #949 from daniel-pittman/bug/3.x/fix-missing-ord-on-185

Implement `Fixnum#ord` for Ruby 1.8.5
(13070) Mark files as loaded before we load

There is a loading cycle that occurs in some situations. It showed up as
not being able to describe certain types because the description
depended on the name of the type's class. For some reason (that is not
entirely clear) the multiple loading of code seems to cause the name of
the class to be wrong.

This patch changes it to mark the file as loaded first, so that we don't
get into a loading cycle.
Merge pull request #950 from zaphod42/bug/2.7.x/13070-error-describing-types

(13070) Mark files as loaded before we load
Merge remote-tracking branch 'origin/2.7.x' into 3.x
zaml: handle multi-line map keys and array values correctly.

The ZAML encoder had some bugs when handling multi-line string values in map
keys and arrays. It also changed behaviour slightly when I modified it for
speed, causing a regression in another case that was correctly handled.

This fixes that, as well as making more robust the process of tagging
structural keys that can span multiple lines.

It also adds some tests to validate that we don't regress again.

This fixes a pre-existing bug in the encoder, as well as my regression.

Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>
Merge branch 'tickets/3.0.x/15398' of https://github.com/masterzen/puppet into 3.x

* 'tickets/3.0.x/15398' of https://github.com/masterzen/puppet:
  (#15398) fix typo in Scope#number? float detection regex

Conflicts:
	lib/puppet/parser/scope.rb
Merge pull request #952 from daniel-pittman/bug/3.x/zaml-map-key-with-embedded-newline-corruption

zaml: handle multi-line map keys and array values correctly.
Merge remote-tracking branch 'origin/3.x'