Skip to content

Commit 0f36d05

Browse files
committed
Address review feedback on server mode PR
- Use exit instead of return in document method for consistency - Replace path.sub regex with delete_prefix in server.rb - Use to_json for safe JavaScript value embedding
1 parent 00c033c commit 0f36d05

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

lib/rdoc/rdoc.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ def document(options)
475475
@store.complete @options.visibility
476476

477477
start_server
478-
return
478+
exit
479479
end
480480

481481
unless @options.coverage_report then

lib/rdoc/server.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def self.live_reload_script(last_change_time)
2727
<<~JS
2828
<script>
2929
(function() {
30-
var lastChange = #{last_change_time};
30+
var lastChange = #{last_change_time.to_json};
3131
setInterval(function() {
3232
fetch('/__status').then(function(r) { return r.json(); }).then(function(data) {
3333
if (data.last_change > lastChange) location.reload();
@@ -196,7 +196,7 @@ def write_response(client, status, content_type, body)
196196
# Serves a static asset (CSS, JS) from the Aliki template directory.
197197

198198
def serve_asset(path)
199-
rel_path = path.sub(%r{\A/}, '')
199+
rel_path = path.delete_prefix("/")
200200
asset_path = File.join(@generator.template_dir, rel_path)
201201
real_asset = File.expand_path(asset_path)
202202
real_template = File.expand_path(@generator.template_dir)
@@ -215,7 +215,7 @@ def serve_asset(path)
215215
# version.
216216

217217
def serve_page(path)
218-
name = path.sub(%r{\A/}, '')
218+
name = path.delete_prefix("/")
219219
name = 'index.html' if name.empty?
220220

221221
html = render_page(name)

0 commit comments

Comments
 (0)