zaru 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/zaru.rb +14 -2
  2. metadata +6 -4
@@ -3,6 +3,10 @@
3
3
  class Zaru
4
4
  CHARACTER_FILTER = /[\x00-\x1F\/\\:\*\?\"<>\|]/u
5
5
  UNICODE_WHITESPACE = /[[:space:]]+/u
6
+ WINDOWS_RESERVED_NAMES =
7
+ %w{CON PRN AUX NUL COM1 COM2 COM3 COM4 COM5
8
+ COM6 COM7 COM8 COM9 LPT1 LPT2 LPT3 LPT4
9
+ LPT5 LPT6 LPT7 LPT8 LPT9}
6
10
 
7
11
  def initialize(filename)
8
12
  @raw = filename.to_s.freeze
@@ -16,7 +20,8 @@ class Zaru
16
20
 
17
21
  # remove characters that aren't allowed cross-OS
18
22
  def sanitize
19
- @sanitized ||= normalize.gsub(CHARACTER_FILTER,'')
23
+ @sanitized ||=
24
+ filter_windows_reserved_names(normalize.gsub(CHARACTER_FILTER,''))
20
25
  end
21
26
 
22
27
  # normalize unicode string and cut off at 255 characters
@@ -32,6 +37,13 @@ class Zaru
32
37
 
33
38
  # convenience method
34
39
  def self.sanitize!(filename)
35
- Zaru.new(filename).to_s
40
+ new(filename).to_s
36
41
  end
42
+
43
+ private
44
+
45
+ def filter_windows_reserved_names(filename)
46
+ WINDOWS_RESERVED_NAMES.include?(filename.upcase) ? 'file' : filename
47
+ end
48
+
37
49
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zaru
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,14 +11,16 @@ bindir: bin
11
11
  cert_chain: []
12
12
  date: 2013-02-03 00:00:00.000000000 Z
13
13
  dependencies: []
14
- description: Filename sanitization for Ruby
14
+ description: Zaru takes a given filename (a string) and normalizes, filters and truncates
15
+ it, so it can be safely used as a filename in modern operating systems. Zaru doesn't
16
+ remove Unicode characters when not necessary.
15
17
  email: thomas@slash7.com
16
18
  executables: []
17
19
  extensions: []
18
20
  extra_rdoc_files: []
19
21
  files:
20
22
  - lib/zaru.rb
21
- homepage: http://rubygems.org/gems/zaru
23
+ homepage: http://github.com/madrobby/zaru
22
24
  licenses: []
23
25
  post_install_message:
24
26
  rdoc_options: []
@@ -41,5 +43,5 @@ rubyforge_project:
41
43
  rubygems_version: 1.8.23
42
44
  signing_key:
43
45
  specification_version: 3
44
- summary: zaru
46
+ summary: Filename sanitization for Ruby
45
47
  test_files: []