webloc 0.0.1 → 0.2.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e8ff9f7c12df7756811c14678b08b8ab6e42839dbb687b802ad37addf372f82d
4
+ data.tar.gz: 71f8eec3e245afe13e755127b519999255547829f3903f7d70b90099434a7493
5
+ SHA512:
6
+ metadata.gz: 82233db761cc8a120f29e0f98f6a285cf2184f3ec9c865feaef060deb1b6021682a604dc1f352ea9af3b9d81fc2dd7fab04a3d3f18e8b923e0f310eeb3e680ae
7
+ data.tar.gz: ce6d621dda047bd22bbc68353f031bcc91d579f3a46c0c2e049606bf9f778fbcb9d3a0ee03d87eef5c4ac3699ba351eb2be99d60a06500c9cef3cd95c036f2d7
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in webloc.gemspec
4
4
  gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2011-2024 Peter Cooper
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # webloc
2
2
 
3
- *webloc* is a Ruby library that can read from and write to <tt>.webloc</tt> files as used on OS X.
3
+ *webloc* is a Ruby library that can read from and write to <tt>.webloc</tt> files as used on macOS. These are a variant of 'plist' format files, specifically used for storing links to URLs.
4
4
 
5
- It works on both Ruby 1.9.2 and 1.8.7 (though development is focused on 1.9.2).
5
+ It works on Ruby 2.7 and up, including Ruby 3.x, and supports URLs of up to 255 characters in length.
6
6
 
7
7
  ## Installation
8
8
 
@@ -10,18 +10,21 @@ It works on both Ruby 1.9.2 and 1.8.7 (though development is focused on 1.9.2).
10
10
 
11
11
  ## Usage
12
12
 
13
- It's pretty simple.
14
-
15
13
  Reading a .webloc file:
16
14
 
17
15
  Webloc.load(ARGV.first).url
18
16
 
19
17
  Writing to a .webloc file:
20
18
 
21
- Webloc.new('http://peterc.org/').save('peterc.webloc')
19
+ Webloc.new('https://rubyweekly.com/').save('rubyweekly.webloc')
20
+
21
+ ## Thanks
22
+
23
+ Thanks is due to Christos Karaiskos for [this article](https://medium.com/@karaiskc/understanding-apples-binary-property-list-format-281e6da00dbd
24
+ ) which helped me understand the plist format a bit more when fixing a bug in 2024.
22
25
 
23
26
  ## License
24
27
 
25
- Copyright (C) 2011 Peter Cooper
28
+ Copyright (C) 2011-2024 Peter Cooper
26
29
 
27
30
  webloc is licensed under the terms of the MIT License
@@ -1,3 +1,3 @@
1
1
  class Webloc
2
- VERSION = "0.0.1"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/webloc.rb CHANGED
@@ -25,14 +25,39 @@ class Webloc
25
25
  end
26
26
 
27
27
  def data
28
- @data = "\x62\x70\x6C\x69\x73\x74\x30\x30\xD1\x01\x02\x53\x55\x52\x4C\x5F\x10"
29
- @data += @url.length.chr
30
- @data += @url
31
- @data += "\x08\x0B\x0F\x00\x00\x00\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
32
- @data += (@url.length + 18).chr
28
+ # PLIST HEADER
29
+ @data = "bplist\x30\x30".bytes
30
+
31
+ # PLIST OBJECT TABLE
32
+ @data += "\xD1\x01\x02".bytes # object 1 is a dictionary
33
+ @data += "\x53URL".bytes # object 2 is an ASCII string of length 3
34
+ @data += "\x5f\x10".bytes # object 3 is an ASCII string with a variable length length encoding (I know..)
35
+ # .. the '0' in \x10 denotes the length can be encoded within 2**0 bytes (i.e. 1!)
36
+ @data += @url.length.chr.bytes # and here is that one byte..
37
+ @data += @url.bytes # and finally the URL itself
38
+
39
+ # This is the offset table
40
+ @data += "\x08\x0B\x0F".bytes # so objects at 0x08, 0x0b and 0x0f
41
+
42
+ # PLIST TRAILER
43
+ # Bytes 0-4 are unused
44
+ @data += "\x00\x00\x00\x00\x00".bytes
45
+ # Byte 5 is the sort version
46
+ @data += "\x00".bytes
47
+ # Byte 6 is how many bytes are needed for each offset table offset
48
+ @data += "\x01".bytes
49
+ @data += "\x01".bytes
50
+ # Bytes 8-15 are how many objects are contained in the plist
51
+ @data += "\x00\x00\x00\x00\x00\x00\x00\x03".bytes
52
+ # Bytes 16-23 are for an offset from the offset table
53
+ @data += "\x00\x00\x00\x00\x00\x00\x00\x00".bytes
54
+ # Bytes 24-31 denote the position of the offset table from the start of the file
55
+ @data += "\x00\x00\x00\x00\x00\x00\x00".bytes + (@url.length + 18).chr.bytes
56
+
57
+ @data = @data.pack('C*')
33
58
  end
34
59
 
35
60
  def save(filename)
36
- File.open(filename, 'w:binary') { |f| f.print data }
61
+ File.open(filename, 'wb') { |f| f.write data }
37
62
  end
38
63
  end
data/test/webloc_test.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'test/unit'
2
2
  require 'webloc'
3
+ require 'tempfile'
3
4
 
4
5
  class WeblocTest < Test::Unit::TestCase
5
6
  def test_webloc_object_requires_url
@@ -19,8 +20,23 @@ class WeblocTest < Test::Unit::TestCase
19
20
  end
20
21
 
21
22
  def test_webloc_generates_valid_data
22
- data = File.read(File.dirname(__FILE__) + '/oldstyle.webloc')
23
- data = data.force_encoding('binary') rescue data
23
+ data = File.read(File.dirname(__FILE__) + '/oldstyle.webloc').b
24
24
  assert_equal data, Webloc.new('https://github.com/peterc/webloc').data
25
25
  end
26
+
27
+ def test_webloc_can_handle_long_urls
28
+ url = "http://example.com/this-is-a-very-long-url-indeed-it-should-easily-go-over-110-characters-for-our-testing-purposes"
29
+ assert_nothing_raised { Webloc.new(url).data }
30
+ end
31
+
32
+ def test_webloc_can_write_file
33
+ file = Tempfile.new('test-webloc')
34
+ begin
35
+ Webloc.new('https://github.com/peterc/webloc').save(file.path)
36
+ assert_equal Webloc.new('https://github.com/peterc/webloc').data, File.read(file.path).b
37
+ ensure
38
+ file.close
39
+ file.unlink
40
+ end
41
+ end
26
42
  end
data/webloc.gemspec CHANGED
@@ -7,10 +7,10 @@ Gem::Specification.new do |s|
7
7
  s.version = Webloc::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Peter Cooper"]
10
- s.email = ["peter@petercooper.co.uk"]
11
- s.homepage = "http://github.com/peterc/webloc"
12
- s.summary = %q{Reads and writes .webloc files on OS X}
13
- s.description = %q{Webloc reads and writes .webloc files on OS X}
10
+ s.email = ["git@peterc.org"]
11
+ s.homepage = "https://github.com/peterc/webloc"
12
+ s.summary = %q{Reads and writes .webloc files on macOS}
13
+ s.description = %q{Webloc reads and writes .webloc files on macOS}
14
14
 
15
15
  s.rubyforge_project = "webloc"
16
16
 
metadata CHANGED
@@ -1,47 +1,39 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: webloc
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 1
9
- version: 0.0.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
10
5
  platform: ruby
11
- authors:
6
+ authors:
12
7
  - Peter Cooper
13
- autorequire:
8
+ autorequire:
14
9
  bindir: bin
15
10
  cert_chain: []
16
-
17
- date: 2011-01-26 00:00:00 +00:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
11
+ date: 2024-01-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
21
14
  name: plist
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
26
17
  - - ">="
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
- version: "0"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
31
20
  type: :runtime
32
- version_requirements: *id001
33
- description: Webloc reads and writes .webloc files on OS X
34
- email:
35
- - peter@petercooper.co.uk
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Webloc reads and writes .webloc files on macOS
28
+ email:
29
+ - git@peterc.org
36
30
  executables: []
37
-
38
31
  extensions: []
39
-
40
32
  extra_rdoc_files: []
41
-
42
- files:
43
- - .gitignore
33
+ files:
34
+ - ".gitignore"
44
35
  - Gemfile
36
+ - LICENSE
45
37
  - README.md
46
38
  - Rakefile
47
39
  - lib/webloc.rb
@@ -50,39 +42,29 @@ files:
50
42
  - test/pliststyle.webloc
51
43
  - test/webloc_test.rb
52
44
  - webloc.gemspec
53
- has_rdoc: true
54
- homepage: http://github.com/peterc/webloc
45
+ homepage: https://github.com/peterc/webloc
55
46
  licenses: []
56
-
57
- post_install_message:
47
+ metadata: {}
48
+ post_install_message:
58
49
  rdoc_options: []
59
-
60
- require_paths:
50
+ require_paths:
61
51
  - lib
62
- required_ruby_version: !ruby/object:Gem::Requirement
63
- none: false
64
- requirements:
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
65
54
  - - ">="
66
- - !ruby/object:Gem::Version
67
- segments:
68
- - 0
69
- version: "0"
70
- required_rubygems_version: !ruby/object:Gem::Requirement
71
- none: false
72
- requirements:
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
73
59
  - - ">="
74
- - !ruby/object:Gem::Version
75
- segments:
76
- - 0
77
- version: "0"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
78
62
  requirements: []
79
-
80
- rubyforge_project: webloc
81
- rubygems_version: 1.3.7
82
- signing_key:
83
- specification_version: 3
84
- summary: Reads and writes .webloc files on OS X
85
- test_files:
63
+ rubygems_version: 3.2.22
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: Reads and writes .webloc files on macOS
67
+ test_files:
86
68
  - test/oldstyle.webloc
87
69
  - test/pliststyle.webloc
88
70
  - test/webloc_test.rb