From 52085b102539743bc7bae24f3e7ef8c97d784a2d Mon Sep 17 00:00:00 2001 From: Styopa Semenukha Date: Mon, 14 Aug 2017 16:48:44 -0400 Subject: [PATCH] Escape single quotes --- lib/hafriedlander/Peg/Compiler/Token/Literal.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/hafriedlander/Peg/Compiler/Token/Literal.php b/lib/hafriedlander/Peg/Compiler/Token/Literal.php index c97a60a..101be06 100644 --- a/lib/hafriedlander/Peg/Compiler/Token/Literal.php +++ b/lib/hafriedlander/Peg/Compiler/Token/Literal.php @@ -6,7 +6,9 @@ class Literal extends Expressionable { function __construct( $value ) { - parent::__construct( 'literal', "'" . substr($value,1,-1) . "'" ); + // escape single quotes + $escaped_value = str_replace('\'', '\\\'', substr($value,1,-1)); + parent::__construct( 'literal', "'" . $escaped_value . "'" ); } function match_code( $value ) {