in reply to Re: strings to json
in thread strings to json

The first solution is broken; it suffers from JSON-injection bugs. For example, try

my $name = 'Mike "The Coder" Smith';

or

my $pass = 'S3KYU\\3e';

Replies are listed 'Best First'.
Re^3: strings to json
by tobyink (Canon) on Jun 24, 2017 at 21:51 UTC

    It's only broken if you change the other code so $name, etc are different.

    But if you change the surrounding code, it's possible to break anything.

      Are you seriously going to argue the inputs are constant? If you really believe that, why did you post such stupid solutions? You should have suggested

      use strict; use warnings; print '{ "mike": 20, "johndeo@test.com": "test" }';

      But no, the OP used variables for a reason. It's because they are variable. And because of that, your first solution is buggy.

        Its what the OP wants