From e74fc2765a9fdfe390eae8bcb46795e4270ef91b Mon Sep 17 00:00:00 2001 From: ccd0 Date: Thu, 15 May 2014 10:02:27 -0700 Subject: [PATCH] move escape function to Build --- src/General/Build.coffee | 3 +++ src/Miscellaneous/FileInfo.coffee | 23 ++++++++++------------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/General/Build.coffee b/src/General/Build.coffee index 310c981a3..9e5b7ab58 100755 --- a/src/General/Build.coffee +++ b/src/General/Build.coffee @@ -2,6 +2,9 @@ Build = staticPath: '//s.4cdn.org/image/' gifIcon: if window.devicePixelRatio >= 2 then '@2x.gif' else '.gif' spoilerRange: {} + escape: (name) -> + name.replace /[&"'<>]/g, (c) -> + {'&': '&', "'": ''', '"': '"', '<': '<', '>': '>'}[c] shortFilename: (filename, isReply) -> # FILENAME SHORTENING SCIENCE: # OPs have a +10 characters threshold. diff --git a/src/Miscellaneous/FileInfo.coffee b/src/Miscellaneous/FileInfo.coffee index 7bcdec103..2f89bbb26 100755 --- a/src/Miscellaneous/FileInfo.coffee +++ b/src/Miscellaneous/FileInfo.coffee @@ -13,7 +13,7 @@ FileInfo = if c of FileInfo.formatters FileInfo.formatters[c].call(post) else - FileInfo.escape s + Build.escape s convertUnit: (size, unit) -> if unit is 'B' return "#{size.toFixed()} Bytes" @@ -24,25 +24,22 @@ FileInfo = else size.toFixed() "#{size} #{unit}" - escape: (name) -> - name.replace /[&"'<>]/g, (c) -> - {'&': '&', "'": ''', '"': '"', '<': '<', '>': '>'}[c] formatters: - t: -> FileInfo.escape @file.URL.match(/\d+\..+$/)[0] - T: -> "#{FileInfo.formatters.t.call @}" - l: -> "#{FileInfo.formatters.n.call @}" - L: -> "#{FileInfo.formatters.N.call @}" + t: -> Build.escape @file.URL.match(/\d+\..+$/)[0] + T: -> "#{FileInfo.formatters.t.call @}" + l: -> "#{FileInfo.formatters.n.call @}" + L: -> "#{FileInfo.formatters.N.call @}" n: -> fullname = @file.name shortname = Build.shortFilename @file.name, @isReply if fullname is shortname - FileInfo.escape fullname + Build.escape fullname else - "#{FileInfo.escape shortname}#{FileInfo.escape fullname}" - N: -> FileInfo.escape @file.name + "#{Build.escape shortname}#{Build.escape fullname}" + N: -> Build.escape @file.name p: -> if @file.isSpoiler then 'Spoiler, ' else '' - s: -> FileInfo.escape @file.size + s: -> Build.escape @file.size B: -> FileInfo.convertUnit @file.sizeInBytes, 'B' K: -> FileInfo.convertUnit @file.sizeInBytes, 'KB' M: -> FileInfo.convertUnit @file.sizeInBytes, 'MB' - r: -> FileInfo.escape (@file.dimensions or 'PDF') + r: -> Build.escape (@file.dimensions or 'PDF')