wikis: normalize Unicode characters in wiki bodies.

* Introduce an abstraction for normalizing attributes. Very loosely
  modeled after https://github.com/fnando/normalize_attributes.
* Normalize wiki bodies to Unicode NFC form.
* Normalize Unicode space characters in wiki bodies (strip zero width
  spaces, normalize line endings to CRLF, normalize Unicode spaces to
  ASCII spaces).
* Trim spaces from the start and end of wiki page bodies. This may cause
  wiki page diffs to show spaces being removed even when the user didn't
  explicitly remove the spaces themselves.
This commit is contained in:
evazion
2020-12-21 03:23:19 -06:00
parent 48ff7c42cd
commit efb836ac02
6 changed files with 76 additions and 5 deletions

View File

@@ -0,0 +1,18 @@
module Normalizable
extend ActiveSupport::Concern
class_methods do
def normalize(attribute, method_name)
define_method("#{attribute}=") do |value|
normalized_value = self.class.send(method_name, value)
super(normalized_value)
end
end
private
def normalize_text(text)
text.unicode_normalize(:nfc).normalize_whitespace.strip
end
end
end