Use page.sha instead of a content-based hash for collision detection.
This commit is contained in:
+3
-3
@@ -176,7 +176,7 @@ module Precious
|
|||||||
@page = page
|
@page = page
|
||||||
@page.version = wiki.repo.log(wiki.ref, @page.path).first
|
@page.version = wiki.repo.log(wiki.ref, @page.path).first
|
||||||
@content = page.text_data
|
@content = page.text_data
|
||||||
@etag = Digest::SHA1.hexdigest(@content)
|
@etag = page.sha
|
||||||
mustache :edit
|
mustache :edit
|
||||||
else
|
else
|
||||||
redirect_to("/create/#{encodeURIComponent(@name)}")
|
redirect_to("/create/#{encodeURIComponent(@name)}")
|
||||||
@@ -279,14 +279,14 @@ module Precious
|
|||||||
end
|
end
|
||||||
|
|
||||||
post '/edit/*' do
|
post '/edit/*' do
|
||||||
etag = params[:etag]
|
etag = params[:etag]
|
||||||
path = "/#{clean_url(sanitize_empty_params(params[:path]))}"
|
path = "/#{clean_url(sanitize_empty_params(params[:path]))}"
|
||||||
page_name = CGI.unescape(params[:page])
|
page_name = CGI.unescape(params[:page])
|
||||||
wiki = wiki_new
|
wiki = wiki_new
|
||||||
page = wiki.paged(page_name, path, exact = true)
|
page = wiki.paged(page_name, path, exact = true)
|
||||||
|
|
||||||
return if page.nil?
|
return if page.nil?
|
||||||
if etag != Digest::SHA1.hexdigest(page.text_data)
|
if etag != page.sha
|
||||||
halt 412, 'For future use: some helpful data for resolving the conflict here.'
|
halt 412, 'For future use: some helpful data for resolving the conflict here.'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user