summaryrefslogtreecommitdiff
path: root/lib/ci
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-05-09 20:19:27 +0300
committerKamil Trzcinski <ayufan@ayufan.eu>2016-05-09 20:19:27 +0300
commit74520f23db51c95b4aea8856fb51c4246785f776 (patch)
treeae6411f58e16b60cba1d5da3c150f07d01852852 /lib/ci
parentbaef6728fa4e8e515ccdeba1ea54da996f322aab (diff)
downloadgitlab-ce-74520f23db51c95b4aea8856fb51c4246785f776.tar.gz
Encode state as base64 string
Diffstat (limited to 'lib/ci')
-rw-r--r--lib/ci/ansi2html.rb13
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/ci/ansi2html.rb b/lib/ci/ansi2html.rb
index d29e68570ff..5fed43aaebd 100644
--- a/lib/ci/ansi2html.rb
+++ b/lib/ci/ansi2html.rb
@@ -90,7 +90,7 @@ module Ci
def convert(raw, new_state)
reset_state
- restore_state(new_state) if new_state && new_state[:offset].to_i < raw.length
+ restore_state(raw, new_state) if new_state
start = @offset
ansi = raw[@offset..-1]
@@ -187,15 +187,20 @@ module Ci
end
def state
- STATE_PARAMS.inject({}) do |h, param|
+ state = STATE_PARAMS.inject({}) do |h, param|
h[param] = send(param)
h
end
+ Base64.urlsafe_encode64(state.to_json)
end
- def restore_state(new_state)
+ def restore_state(raw, new_state)
+ state = Base64.urlsafe_decode64(new_state)
+ state = JSON.parse(state, symbolize_names: true)
+ return if state[:offset].to_i > raw.length
+
STATE_PARAMS.each do |param|
- send("#{param}=".to_sym, new_state[param])
+ send("#{param}=".to_sym, state[param])
end
end