webloc 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e8ff9f7c12df7756811c14678b08b8ab6e42839dbb687b802ad37addf372f82d
4
- data.tar.gz: 71f8eec3e245afe13e755127b519999255547829f3903f7d70b90099434a7493
3
+ metadata.gz: 498d11e48961e5843a3a25fafb71f4738ebc10733037145ea30a17f176abcaa2
4
+ data.tar.gz: 78beeadfdafd1a7f414fc6f7b69c6fd24819ed79bb39a9148e72e1bc38089416
5
5
  SHA512:
6
- metadata.gz: 82233db761cc8a120f29e0f98f6a285cf2184f3ec9c865feaef060deb1b6021682a604dc1f352ea9af3b9d81fc2dd7fab04a3d3f18e8b923e0f310eeb3e680ae
7
- data.tar.gz: ce6d621dda047bd22bbc68353f031bcc91d579f3a46c0c2e049606bf9f778fbcb9d3a0ee03d87eef5c4ac3699ba351eb2be99d60a06500c9cef3cd95c036f2d7
6
+ metadata.gz: 99b273c4af784bdafe2cde8166da2c3672a263d2e412f0f1547e70ef4b8bf8de74185a13b1050e5c16b713e3f7b8c67baabe9f25b1366ee4e86876a95a368740
7
+ data.tar.gz: fdbd68bb1239b9b35b1eb8c3d3ef8302d69d8a48eca6830bf636eb693f6e8c9a35e19af02148fda21a2d5a2ce3be1e3b7bef8186d7917dd8c40f73a699557e60
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  pkg/*
2
2
  *.gem
3
3
  .bundle
4
+ .DS_Store
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
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 Ruby 2.7 and up, including Ruby 3.x, and supports URLs of up to 255 characters in length.
5
+ It works on Ruby 2.7 and up, including Ruby 3.x, and supports URLs of up to 2048 characters in length (and probably longer, but this is around the de facto limit for URLs in most systems).
6
6
 
7
7
  ## Installation
8
8
 
@@ -1,3 +1,3 @@
1
1
  class Webloc
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/webloc.rb CHANGED
@@ -13,9 +13,16 @@ class Webloc
13
13
 
14
14
  if data !~ /\<plist/
15
15
  offset = (data =~ /SURL_/)
16
- length = data[offset + 6]
17
- length = length.ord rescue length
18
- url = data[offset + 7,length]
16
+ length_offset = 7
17
+ if data[offset + 5] == "\x10"
18
+ length = data[offset + 6]
19
+ length = length.unpack('C')[0]
20
+ elsif data[offset + 5] == "\x11"
21
+ length_offset = 8
22
+ length = data[offset + 6] + data[offset + 7]
23
+ length = length.unpack('S>')[0]
24
+ end
25
+ url = data[offset + length_offset,length]
19
26
  else
20
27
  url = Plist::parse_xml(filename)['URL'] rescue nil
21
28
  end
@@ -30,10 +37,18 @@ class Webloc
30
37
 
31
38
  # PLIST OBJECT TABLE
32
39
  @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..
40
+ @data += "SURL".bytes # object 2
41
+
42
+ length_suffix = @url.length > 255 ? "\x11" : "\x10"
43
+ @data += ("\x5f" + length_suffix).bytes # object 3 is an ASCII string with a variable length length encoding (I know..)
44
+ # .. the '0' in \x10 denotes the length can be encoded within 2**0 bytes (i.e. 1)
45
+ # .. the '1' in \x11 denotes the length can be encoded within 2**1 bytes (i.e. 2)
46
+
47
+ if @url.length > 255
48
+ @data += [@url.length].pack('S>').bytes
49
+ else
50
+ @data += [@url.length].pack('C').bytes
51
+ end
37
52
  @data += @url.bytes # and finally the URL itself
38
53
 
39
54
  # This is the offset table
@@ -52,7 +67,7 @@ class Webloc
52
67
  # Bytes 16-23 are for an offset from the offset table
53
68
  @data += "\x00\x00\x00\x00\x00\x00\x00\x00".bytes
54
69
  # 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
70
+ @data += "\x00\x00\x00\x00\x00\x00".bytes + [@url.length + 18].pack('S>').bytes
56
71
 
57
72
  @data = @data.pack('C*')
58
73
  end
data/test/webloc_test.rb CHANGED
@@ -25,8 +25,16 @@ class WeblocTest < Test::Unit::TestCase
25
25
  end
26
26
 
27
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"
28
+ url = "http://example.com/this-is-a-very-long-url-abcde" + ('a' * 2000)
29
29
  assert_nothing_raised { Webloc.new(url).data }
30
+ file = Tempfile.new('test-long-webloc')
31
+ begin
32
+ Webloc.new(url).save(file.path)
33
+ assert_equal url, Webloc.load(file.path).url
34
+ ensure
35
+ file.close
36
+ file.unlink
37
+ end
30
38
  end
31
39
 
32
40
  def test_webloc_can_write_file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webloc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Cooper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-26 00:00:00.000000000 Z
11
+ date: 2024-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: plist
@@ -60,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  requirements: []
63
- rubygems_version: 3.2.22
63
+ rubygems_version: 3.5.3
64
64
  signing_key:
65
65
  specification_version: 4
66
66
  summary: Reads and writes .webloc files on macOS