mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-26 19:36:22 +00:00
Merge branch 'jekyll-service' into panel.sutty.nl
This commit is contained in:
commit
46e304b317
7 changed files with 42 additions and 7 deletions
|
@ -11,6 +11,17 @@ module ActiveStorage
|
|||
blob = ActiveStorage::Blob.create_before_direct_upload!(service_name: session[:service_name], **blob_args)
|
||||
render json: direct_upload_json(blob)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Normalizar los caracteres unicode en los nombres de archivos
|
||||
# para que puedan propagarse correctamente a través de todo el
|
||||
# stack.
|
||||
def blob_args
|
||||
params.require(:blob).permit(:filename, :byte_size, :checksum, :content_type, metadata: {}).to_h.symbolize_keys.tap do |ba|
|
||||
ba[:filename] = ba[:filename].unicode_normalize(:nfkc)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
21
app/lib/action_dispatch/http/uploaded_file_decorator.rb
Normal file
21
app/lib/action_dispatch/http/uploaded_file_decorator.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module ActionDispatch
|
||||
module Http
|
||||
# Normaliza los nombres de archivo para que se propaguen
|
||||
# correctamente a través de todo el stack.
|
||||
module UploadedFileDecorator
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
# Devolver el nombre de archivo con caracteres unicode
|
||||
# normalizados
|
||||
def original_filename
|
||||
@original_filename.unicode_normalize(:nfkc)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
ActionDispatch::Http::UploadedFile.include ActionDispatch::Http::UploadedFileDecorator
|
|
@ -12,6 +12,6 @@ class MetadataMarkdown < MetadataText
|
|||
# markdown y se eliminan autolinks. Mejor es habilitar la generación
|
||||
# SAFE de CommonMark en la configuración del sitio.
|
||||
def sanitize(string)
|
||||
string
|
||||
string.unicode_normalize(:nfkc)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -25,6 +25,6 @@ class MetadataMarkdownContent < MetadataText
|
|||
# markdown y se eliminan autolinks. Mejor es deshabilitar la
|
||||
# generación SAFE de CommonMark en la configuración del sitio.
|
||||
def sanitize(string)
|
||||
string.tr("\r", '')
|
||||
string.tr("\r", '').unicode_normalize(:nfkc)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,7 +19,7 @@ class MetadataPermalink < MetadataString
|
|||
# puntos suspensivos, la primera / para que siempre sea relativa y
|
||||
# agregamos una / al final si la ruta no tiene extensión.
|
||||
def sanitize(value)
|
||||
value = value.strip.gsub('..', '/').gsub('./', '').squeeze('/')
|
||||
value = value.strip.unicode_normalize(:nfkc).gsub('..', '/').gsub('./', '').squeeze('/')
|
||||
value = value[1..-1] if value.start_with? '/'
|
||||
value += '/' if File.extname(value).blank?
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ class MetadataString < MetadataTemplate
|
|||
def sanitize(string)
|
||||
return '' if string.blank?
|
||||
|
||||
sanitizer.sanitize(string.strip,
|
||||
sanitizer.sanitize(string.strip.unicode_normalize(:nfkc),
|
||||
tags: [],
|
||||
attributes: []).strip.html_safe
|
||||
end
|
||||
|
|
|
@ -184,9 +184,12 @@ MetadataTemplate = Struct.new(:site, :document, :name, :label, :type,
|
|||
return if string.nil?
|
||||
return string unless string.is_a? String
|
||||
|
||||
sanitizer.sanitize(string.tr("\r", ''),
|
||||
sanitizer
|
||||
.sanitize(string.tr("\r", '').unicode_normalize(:nfkc),
|
||||
tags: allowed_tags,
|
||||
attributes: allowed_attributes).strip.html_safe
|
||||
attributes: allowed_attributes)
|
||||
.strip
|
||||
.html_safe
|
||||
end
|
||||
|
||||
def sanitizer
|
||||
|
|
Loading…
Reference in a new issue