From 4941aea170398190e83cdd103d7a012eb335c341 Mon Sep 17 00:00:00 2001 From: Xabier de Zuazo Date: Thu, 17 Sep 2015 14:20:04 +0200 Subject: [PATCH] Config library: escape JSON backslash and quotes for PHP --- libraries/config.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libraries/config.rb b/libraries/config.rb index 6ced283..a4880c7 100644 --- a/libraries/config.rb +++ b/libraries/config.rb @@ -11,6 +11,14 @@ def initialize(file) read end + protected + + def options_php_json + @options.to_json.gsub('\\', '\\\\\\').gsub("'", "\\\\'") + end + + public + def [](index) @options[index] end @@ -38,7 +46,7 @@ def read() begin return unless ::File.exists?(@file) f = IO.popen('php', 'r+') - f.write "