rack_web_console 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dcd27bbf7602dceca8c4f8a932e4357b6fa71a86
4
- data.tar.gz: 41d49308a3c17ebca10343b53151f4b89954edd2
3
+ metadata.gz: 1dfaeac9ee45c324241bea12915d58f6bbd5be2e
4
+ data.tar.gz: 2bd64bc6b3e89fc89610a7c570136237b300888b
5
5
  SHA512:
6
- metadata.gz: abd3d2c15e9dead6eb862166110c2d3345c6a316bdd61d6c2df9228e93877ed569cae64281169cd940a688b41b4afb94661122fa2aa1db9c03dca483594e6095
7
- data.tar.gz: bff88e035f39d359e6c064ae16ce55f178c83f8f824a80ed34efb0118e4fc803636404da801f489b9e7add0c4a5fee9a57ad0ade3bb7af3d63b31dd54d54481d
6
+ metadata.gz: 85a986e233d90c6723b59b35a8d5fa310ec6db0820b25b61c8b1dd4a85e069e53a3074817fa517fe27fd800ab08439228213a2fa301dc9d9acf02d60b0fd9269
7
+ data.tar.gz: 422c7aa741fbae714a64ba95ca3530f86d98ec4a321519241897269a1155f2b315fb243140bbc3b8fc422babd27f51e71c7901df360aa3afd90566101316d7f0
data/.travis.yml CHANGED
@@ -2,4 +2,7 @@ sudo: false
2
2
  language: ruby
3
3
  rvm:
4
4
  - 2.3.1
5
+ - jruby-9.1.2.0
5
6
  before_install: gem install bundler -v 1.12.5
7
+ env:
8
+ - WAIT_FOR_BOOT_TIME=1
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Rack Web Console
1
+ # Rack Web Console [![Build Status](https://travis-ci.org/rosenfeld/rack_web_console.svg?branch=master)](https://travis-ci.org/rosenfeld/rack_web_console)
2
2
 
3
3
  Rack Web Console is a simple Rack app class that allows one to run arbitrary Ruby code on a given
4
4
  binding, which may be useful in development mode to test some code in a given context. This is
@@ -96,6 +96,11 @@ Thread.current[:rack_console_capture_all] = true
96
96
  Thread.start{ puts 'now it should be displayed in the browser' }.join
97
97
  ```
98
98
 
99
+ ### Shortcuts from inside the textarea
100
+
101
+ - Ctrl+Enter: Run code
102
+ - Esc, Esc: Clear output
103
+
99
104
  ## Development
100
105
 
101
106
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec`
@@ -21,6 +21,7 @@
21
21
  <div id="results"></div>
22
22
 
23
23
  <script>
24
+ ;(function(){
24
25
  var run_path = '', lastEscTime = 0,
25
26
  results = $el('results'), runScriptButton = $el('run-script'),
26
27
  clearResultsButton = $el('clear-results'), script = $el('script'), request
@@ -46,7 +47,8 @@
46
47
  div.innerHTML = this.responseText
47
48
  results.appendChild(div)
48
49
  }
49
- request.send('script=' + encodeURIComponent(script.value))
50
+ request.send('script=' + encodeURIComponent(script.value) + '&token=' +
51
+ encodeURIComponent('<%= token %>'))
50
52
  }
51
53
  function onKeyDown(ev) {
52
54
  if (ev.ctrlKey && ev.keyCode == 13) runScript() // Ctrl + Enter
@@ -55,6 +57,7 @@
55
57
  lastEscTime = new Date().getTime()
56
58
  }
57
59
  }
60
+ })();
58
61
  </script>
59
62
  </body>
60
63
  </html>
@@ -1,3 +1,3 @@
1
1
  class RackConsole
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -1,5 +1,6 @@
1
1
  require 'erb'
2
2
  require 'cgi'
3
+ require 'securerandom'
3
4
  require_relative 'rack_console/version'
4
5
  require_relative 'rack_console/cookie_script_storage'
5
6
  require_relative 'rack_console/output_capture'
@@ -7,8 +8,9 @@ require_relative 'rack_console/output_capture'
7
8
  class RackConsole
8
9
  VIEW_TEMPLATE = ::File.join __dir__, 'rack-console-view.erb'
9
10
 
10
- def initialize(_binding = binding, storage: ->(env){ CookieScriptStorage.new env })
11
+ def initialize(_binding = binding, storage: ->(env){ CookieScriptStorage.new env }, token: nil)
11
12
  @storage, @binding = storage, _binding
13
+ @@token ||= token || SecureRandom.base64(32)
12
14
  end
13
15
 
14
16
  def call(env)
@@ -20,8 +22,10 @@ class RackConsole
20
22
 
21
23
 
22
24
  def process_script(env)
23
- return [403, {}, []] unless same_origin?(env)
24
- script = CGI.unescape env['rack.input'].read.sub(/\Ascript=/, '')
25
+ params = CGI.parse env['rack.input'].read
26
+ token = params['token']&.first.to_s
27
+ return [403, {}, []] unless same_origin?(env) && token == @@token
28
+ script = params['script'].first
25
29
  @_storage&.script=(script)
26
30
  result = []
27
31
  (oc = OutputCapture.new).capture do
@@ -52,6 +56,7 @@ class RackConsole
52
56
 
53
57
  def view_response(env)
54
58
  script = (s = @_storage&.script) ? ::ERB::Util.h(s) : ''
59
+ token = @@token
55
60
  ::ERB.new(::File.read view_template).result binding
56
61
  end
57
62
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack_web_console
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Rosenfeld Rosas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-22 00:00:00.000000000 Z
11
+ date: 2016-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler