win32-xpath 1.0.4 → 1.1.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
  SHA1:
3
- metadata.gz: abfaf67e2e2d0e7fc498fc836f6678dc37defa89
4
- data.tar.gz: df097de20bcfc014b5ca618734f42e9d1c5a177a
3
+ metadata.gz: a356787d2a824c84435d4e0030d2332bc0e608c7
4
+ data.tar.gz: aa3c03d68d1cf089ec4cf98e459305d1b23e5f83
5
5
  SHA512:
6
- metadata.gz: 123f110e37a7e28be35a8aa1c345df61b715f148da2f0171e22b04ac455e38f5ed5ff75b614f9d4741e1699e230cabf50318c15d824b0c9788c6cef2f6c37bcf
7
- data.tar.gz: dc9fccc5225d2725c65fa629dd48c7cac9dfce7ada2f4e859c5c3ecf7cfd8f41cd8719ec5a1f31987d0d19cca98cfbbbef4022834025dc63e719bfb221ac8f08
6
+ metadata.gz: 319c66c30e057d2b7dfdc0fd92146981939e8231dc8337d8d6e8232ccc9ec49678de0713ea7ebcd631e33ffa95839b2bd0773c0bf665c6d8a47dd20ef5b57f27
7
+ data.tar.gz: 3d56bec08b78598926082214bed54e7631147c22e676d0f09fc794d5b05ef919d44263ad0d7a28e456dd426296a5e95c9419b831dcf8aecebce96dd1b09786c1
Binary file
data.tar.gz.sig CHANGED
Binary file
data/CHANGES CHANGED
@@ -1,3 +1,10 @@
1
+ = 1.1.0 - 11-Jun-2016
2
+ * Changed license to Apache 2.0.
3
+ * Use PathCchXXX functions wherever I could that had not already been
4
+ put into place.
5
+ * Removed the "futzing" directory and contents.
6
+ * Added an appveyor.yml file.
7
+
1
8
  = 1.0.4 - 26-Nov-2015
2
9
  * This gem is now signed.
3
10
 
data/MANIFEST CHANGED
@@ -1,9 +1,9 @@
1
+ appveyor.yml
1
2
  bench/bench_win32_xpath.rb
2
3
  CHANGES
3
4
  certs/djberg96_pub.pem
4
5
  ext/extconf.rb
5
6
  ext/win32/xpath.c
6
- futzing/futz.rb
7
7
  Rakefile
8
8
  README
9
9
  test/test_win32_xpath.rb
data/README CHANGED
@@ -45,16 +45,10 @@
45
45
  Park Heesob for encoding advice and help.
46
46
 
47
47
  == License
48
- Artistic 2.0
48
+ Apache 2.0
49
49
 
50
- == Contributions
51
- Although this library is free, please consider having your company
52
- setup a gittip if used by your company professionally.
53
-
54
- http://www.gittip.com/djberg96/
55
-
56
50
  == Copyright
57
- (C) 2003-2015 Daniel J. Berger, All Rights Reserved
51
+ (C) 2003-2016 Daniel J. Berger, All Rights Reserved
58
52
 
59
53
  == Warranty
60
54
  This package is provided "as is" and without any express or
@@ -0,0 +1,35 @@
1
+ version: '{build}'
2
+ branches:
3
+ only:
4
+ - master
5
+ skip_tags: true
6
+ environment:
7
+ matrix:
8
+ - ruby_version: 21
9
+ ruby_dir: 2.1.0
10
+ - ruby_version: 21-x64
11
+ ruby_dir: 2.1.0
12
+ - ruby_version: 22
13
+ ruby_dir: 2.2.0
14
+ - ruby_version: 22-x64
15
+ ruby_dir: 2.2.0
16
+ install:
17
+ - ps: >-
18
+ $env:path = "C:\Ruby" + $env:ruby_version + "\bin;" + $env:path
19
+
20
+ $tpath = "C:\Ruby" + $env:ruby_version + "\lib\ruby\" + $env:ruby_dir + "\test"
21
+
22
+ if ((test-path $tpath) -eq $True){ rm -recurse -force $tpath }
23
+
24
+ gem update --system > $null
25
+
26
+ if ((gem query -i test-unit -v ">= 3.0") -eq $False){ gem install test-unit --no-document }
27
+ cache:
28
+ - C:\Ruby21\lib\ruby\gems\2.1.0
29
+ - C:\Ruby21-x64\lib\ruby\gems\2.1.0
30
+ - C:\Ruby22\lib\ruby\gems\2.2.0
31
+ - C:\Ruby22-x64\lib\ruby\gems\2.2.0
32
+ build: off
33
+ test_script:
34
+ - cmd: rake
35
+ deploy: off
@@ -1,21 +1,21 @@
1
- -----BEGIN CERTIFICATE-----
2
- MIIDcDCCAligAwIBAgIBATANBgkqhkiG9w0BAQUFADA/MREwDwYDVQQDDAhkamJl
3
- cmc5NjEVMBMGC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ueY0viwGDVP1BNGFC+yXcb7u2GlK+nEMCORqzURbYPf7
16
+ tL+/hzmePIRz7i30UM//64GI1NLv9jl7nIwjhPpXpf7/lu2I9hOTsvwSumb5UiKC
17
+ /sqBxI3sfj9pr79Wpv4MuikX1XPik7Ncb7NPsJPw06Lvyc3Hkg5X2XpPtLtS+Gr2
18
+ wKJnmzb5rIPS1cmsqv0M9LPWflzfwoZ/SpnmhagP+g05p8bRNKjZSA2iImM/GyYZ
19
+ EJYzxdPOrx2n6NYR3Hk+vHP0U7UBSveI6+qx+ndQYaeyCn+GRX2PKS9h66YF/Q1V
20
+ tGSHgAmcLlkdGgan182qsE/4kKM=
21
+ -----END CERTIFICATE-----
@@ -10,9 +10,10 @@
10
10
 
11
11
  #ifdef HAVE_PATHCCH_H
12
12
  #include <pathcch.h>
13
- #endif
14
-
13
+ #define MAX_WPATH PATHCCH_MAX_CCH
14
+ #else
15
15
  #define MAX_WPATH MAX_PATH * sizeof(wchar_t)
16
+ #endif
16
17
 
17
18
  // Equivalent to raise SystemCallError.new(string, errnum)
18
19
  void rb_raise_syserr(const char* msg, DWORD errnum){
@@ -119,6 +120,9 @@ wchar_t* expand_tilde(){
119
120
  wchar_t* temp;
120
121
  const wchar_t* env2 = L"HOMEPATH";
121
122
  env = L"HOMEDRIVE";
123
+ #ifdef HAVE_PATHCCH_H
124
+ HRESULT hr;
125
+ #endif
122
126
 
123
127
  // If neither are found then raise an error
124
128
  size = GetEnvironmentVariableW(env, NULL, 0);
@@ -140,8 +144,20 @@ wchar_t* expand_tilde(){
140
144
  rb_raise_syserr("GetEnvironmentVariable", GetLastError());
141
145
  }
142
146
 
143
- if(!PathAppendW(home, temp))
147
+ #ifdef HAVE_PATHCCH_H
148
+ hr = PathCchAppendEx(home, MAX_WPATH, temp, 1);
149
+ if(hr != S_OK){
150
+ ruby_xfree(home);
151
+ ruby_xfree(temp);
152
+ rb_raise_syserr("PathCchAppendEx", hr);
153
+ }
154
+ #else
155
+ if(!PathAppendW(home, temp)){
156
+ ruby_xfree(home);
157
+ ruby_xfree(temp);
144
158
  rb_raise_syserr("PathAppend", GetLastError());
159
+ }
160
+ #endif
145
161
  }
146
162
  else{
147
163
  home = (wchar_t*)ruby_xmalloc(MAX_WPATH);
@@ -204,7 +220,7 @@ static VALUE rb_xpath(int argc, VALUE* argv, VALUE self){
204
220
  rb_econv_close(ec);
205
221
  }
206
222
 
207
- rb_str_modify_expand(v_path, MAX_PATH);
223
+ rb_str_modify_expand(v_path, MAX_WPATH);
208
224
 
209
225
  // Make our path a wide string for later functions
210
226
  length = MultiByteToWideChar(CP_UTF8, 0, RSTRING_PTR(v_path), -1, NULL, 0);
@@ -229,17 +245,15 @@ static VALUE rb_xpath(int argc, VALUE* argv, VALUE self){
229
245
  }
230
246
  else{
231
247
  #ifdef HAVE_PATHCCHAPPENDEX
232
- HRESULT result;
233
- wchar_t buffer[PATHCCH_MAX_CCH];
234
-
235
- wcscpy_s(buffer, PATHCCH_MAX_CCH, expand_tilde(path));
236
-
237
- result = PathCchAppendEx(buffer, MAX_PATH, ++ptr, PATHCCH_ALLOW_LONG_PATHS);
248
+ HRESULT hr;
249
+ home = expand_tilde(path);
238
250
 
239
- if (result != S_OK)
240
- rb_raise_syserr("PathCchAppend", result);
251
+ hr = PathCchAppendEx(home, MAX_WPATH, ++ptr, 1);
241
252
 
242
- home = &buffer[0];
253
+ if(hr != S_OK){
254
+ ruby_xfree(home);
255
+ rb_raise_syserr("PathCchAppendEx", hr);
256
+ }
243
257
  #else
244
258
  home = expand_tilde(path);
245
259
 
@@ -258,6 +272,9 @@ static VALUE rb_xpath(int argc, VALUE* argv, VALUE self){
258
272
  wchar_t* dir;
259
273
  VALUE v_dir;
260
274
  rb_encoding* dir_encoding;
275
+ #ifdef HAVE_PATHCCH_H
276
+ HRESULT hr;
277
+ #endif
261
278
 
262
279
  dir_encoding = rb_enc_get(v_dir_orig);
263
280
 
@@ -272,10 +289,10 @@ static VALUE rb_xpath(int argc, VALUE* argv, VALUE self){
272
289
  }
273
290
 
274
291
  // Prep string for modification
275
- rb_str_modify_expand(v_dir, MAX_PATH);
292
+ rb_str_modify_expand(v_dir, MAX_WPATH);
276
293
 
277
294
  length = MultiByteToWideChar(CP_UTF8, 0, RSTRING_PTR(v_dir), -1, NULL, 0);
278
- dir = (wchar_t*)ruby_xmalloc(MAX_PATH * sizeof(wchar_t));
295
+ dir = (wchar_t*)ruby_xmalloc(MAX_WPATH * sizeof(wchar_t));
279
296
 
280
297
  if (!MultiByteToWideChar(CP_UTF8, 0, RSTRING_PTR(v_dir), -1, dir, length)){
281
298
  ruby_xfree(dir);
@@ -292,10 +309,19 @@ static VALUE rb_xpath(int argc, VALUE* argv, VALUE self){
292
309
  else{
293
310
  dir = expand_tilde();
294
311
 
312
+ #ifdef HAVE_PATHCCH_H
313
+ hr = PathCchAppendEx(dir, MAX_WPATH, ++ptr, 1);
314
+
315
+ if(hr != S_OK){
316
+ ruby_xfree(dir);
317
+ rb_raise_syserr("PathCchAppendEx", hr);
318
+ }
319
+ #else
295
320
  if (!PathAppendW(dir, ++ptr)){
296
321
  ruby_xfree(dir);
297
322
  rb_raise_syserr("PathAppend", GetLastError());
298
323
  }
324
+ #endif
299
325
  }
300
326
  }
301
327
 
@@ -303,10 +329,20 @@ static VALUE rb_xpath(int argc, VALUE* argv, VALUE self){
303
329
  path = dir;
304
330
 
305
331
  if (PathIsRelativeW(path)){
332
+
333
+ #ifdef HAVE_PATHCCH_H
334
+ hr = PathCchAppendEx(dir, MAX_WPATH, path, 1);
335
+
336
+ if(hr != S_OK){
337
+ ruby_xfree(dir);
338
+ rb_raise_syserr("PathCchAppendEx", hr);
339
+ }
340
+ #else
306
341
  if(!PathAppendW(dir, path)){
307
342
  ruby_xfree(dir);
308
343
  rb_raise_syserr("PathAppend", GetLastError());
309
344
  }
345
+ #endif
310
346
 
311
347
  // Remove leading slashes from relative paths
312
348
  if (dir[0] == L'\\')
@@ -350,7 +386,11 @@ static VALUE rb_xpath(int argc, VALUE* argv, VALUE self){
350
386
  }
351
387
 
352
388
  // Strip all trailing backslashes
389
+ #ifdef HAVE_PATHCCH_H
390
+ while (PathCchRemoveBackslash(path, wcslen(path)+1) == S_OK);
391
+ #else
353
392
  while (!*PathRemoveBackslashW(path));
393
+ #endif
354
394
 
355
395
  // First call, get the length
356
396
  length = GetFullPathNameW(path, 0, buffer, NULL);
@@ -65,6 +65,12 @@ class Test_XPath < Test::Unit::TestCase
65
65
  assert_equal(File.join(@root, 'foo.rb'), File.expand_path("#{@root}foo.rb/"))
66
66
  end
67
67
 
68
+ test "removes trailing slashes from relative path" do
69
+ assert_equal(File.join(@pwd, 'foo'), File.expand_path("foo/"))
70
+ assert_equal(File.join(@pwd, 'foo'), File.expand_path("foo//"))
71
+ assert_equal(File.join(@pwd, 'foo'), File.expand_path("foo\\\\\\"))
72
+ end
73
+
68
74
  test "removes trailing spaces from absolute path" do
69
75
  assert_equal(File.join(@root, 'foo'), File.expand_path("#{@root}foo "))
70
76
  end
@@ -2,9 +2,9 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'win32-xpath'
5
- spec.version = '1.0.4'
5
+ spec.version = '1.1.0'
6
6
  spec.author = 'Daniel J. Berger'
7
- spec.license = 'Artistic 2.0'
7
+ spec.license = 'Apache 2.0'
8
8
  spec.email = 'djberg96@gmail.com'
9
9
  spec.homepage = 'http://github.com/djberg96/win32-xpath'
10
10
  spec.summary = 'Revamped File.expand_path for Windows'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: win32-xpath
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
@@ -30,7 +30,7 @@ cert_chain:
30
30
  EJYzxdPOrx2n6NYR3Hk+vHP0U7UBSveI6+qx+ndQYaeyCn+GRX2PKS9h66YF/Q1V
31
31
  tGSHgAmcLlkdGgan182qsE/4kKM=
32
32
  -----END CERTIFICATE-----
33
- date: 2015-11-26 00:00:00.000000000 Z
33
+ date: 2016-06-12 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: rake
@@ -73,6 +73,7 @@ extra_rdoc_files:
73
73
  - CHANGES
74
74
  - MANIFEST
75
75
  files:
76
+ - appveyor.yml
76
77
  - bench
77
78
  - bench/bench_win32_xpath.rb
78
79
  - certs
@@ -82,9 +83,6 @@ files:
82
83
  - ext/extconf.rb
83
84
  - ext/win32
84
85
  - ext/win32/xpath.c
85
- - futzing
86
- - futzing/futz.rb
87
- - futzing/test.rb
88
86
  - MANIFEST
89
87
  - Rakefile
90
88
  - README
@@ -93,7 +91,7 @@ files:
93
91
  - win32-xpath.gemspec
94
92
  homepage: http://github.com/djberg96/win32-xpath
95
93
  licenses:
96
- - Artistic 2.0
94
+ - Apache 2.0
97
95
  metadata: {}
98
96
  post_install_message:
99
97
  rdoc_options: []
@@ -111,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
109
  version: '0'
112
110
  requirements: []
113
111
  rubyforge_project:
114
- rubygems_version: 2.4.8
112
+ rubygems_version: 2.6.4
115
113
  signing_key:
116
114
  specification_version: 4
117
115
  summary: Revamped File.expand_path for Windows
metadata.gz.sig CHANGED
Binary file
@@ -1,71 +0,0 @@
1
- require 'win32/xpath'
2
- require 'tmpdir'
3
-
4
- #p File.expand_path("~djberge", "foo")
5
- #p File.expand_path("~/foo")
6
- #p File.expand_path("", "~djberge")
7
- #p File.expand_path("~djberge")
8
- #p File.expand_path("~djberge/foo/bar")
9
- #p File.expand_path("~bogus")
10
-
11
- ENV['HOME'] = nil
12
- ENV['USERPROFILE'] = nil
13
- ENV['HOMEDRIVE'] = "D:/"
14
- #ENV['USERPROFILE'] = "C:/bogus"
15
- p File.expand_path("~")
16
-
17
- #p File.expand_path("foo", "~")
18
- #p File.expand_path("foo", "~")
19
- #p File.expand_path("", "~")
20
- #p File.expand_path("", "~")
21
- #p File.expand_path("foo", "~/bar")
22
- #p File.expand_path("foo", "~/bar")
23
- #p File.expand_path("")
24
- #p File.expand_path("C:/foo/bar")
25
- #p File.expand_path("C:/foo/bar///")
26
- #p File.expand_path('foo', Dir.tmpdir)
27
- #p File.expand_path("C:/foo/bar", "D:/foo")
28
- #p File.expand_path("foo")
29
- #p File.expand_path("foo", "bar")
30
-
31
- #ENV['HOME'] = nil
32
- #ENV['USERPROFILE'] = nil
33
- #p File.expand_path("~")
34
-
35
- #path = "../a"
36
- #tmp = Dir.tmpdir
37
-
38
- #p path
39
- #p tmp
40
-
41
- #100.times{
42
- # File.expand_path(path, tmp)
43
- # File.expand_path('foo', tmp)
44
- #}
45
-
46
- #p path
47
- #p tmp
48
-
49
- #p File.expand_path('../a', tmp)
50
-
51
- #p File.expand_path('../a', 'foo')
52
- #p File.expand_path('../a', 'foo')
53
- #p File.expand_path('../a', 'C:/foo')
54
- #p File.expand_path('../a', 'C:/foo')
55
-
56
-
57
- =begin
58
- p File.expand_path("/foo").tainted?
59
- p File.expand_path("foo").tainted? # True
60
- p File.expand_path("foo".taint).tainted? # True
61
- p File.expand_path("C:/foo").tainted? # False
62
- p File.expand_path("C:/foo".taint).tainted? # True
63
- =end
64
-
65
- =begin
66
- p File.expand_path("~")
67
- p File.expand_path("~/foo")
68
- p File.expand_path("//foo/bar")
69
- p File.expand_path("//foo/bar//")
70
- p File.expand_path("//foo/bar//")
71
- =end
@@ -1,90 +0,0 @@
1
- require 'ffi'
2
-
3
- class Windows
4
- extend FFI::Library
5
- typedef :ulong, :dword
6
-
7
- ffi_lib :shlwapi
8
-
9
- attach_function :PathCanonicalizeA, [:buffer_out, :string], :bool
10
- attach_function :PathStripToRootA, [:pointer], :bool
11
- attach_function :PathIsRelativeA, [:string], :bool
12
- attach_function :PathAppendA, [:buffer_out, :string], :bool
13
- attach_function :PathSkipRootA, [:string], :string
14
- attach_function :PathIsNetworkPathA, [:string], :bool
15
-
16
- ffi_lib :kernel32
17
- attach_function :GetFullPathNameA, [:string, :dword, :buffer_out, :pointer], :dword
18
-
19
- def xpath(path, dir=nil)
20
- path = path.tr("/", "\\")
21
-
22
- buf = 0.chr * 512
23
-
24
- p path
25
- p PathIsRelativeA(path)
26
-
27
- if !PathCanonicalizeA(buf, path)
28
- raise
29
- end
30
-
31
- p buf.strip
32
-
33
- #p dir
34
- #p path
35
-
36
- #regex = /\A(\w):([^\\]+)(.*)/i
37
- =begin
38
- if m = regex.match(path)
39
- drive = m.captures[0]
40
- path = m.captures[1..-1].join
41
- p drive
42
- p path
43
- end
44
- =end
45
-
46
- #p PathIsNetworkPathA(path)
47
- #p PathSkipRootA(path)
48
- #p PathIsRelativeA(path)
49
-
50
- =begin
51
- buf = 0.chr * 1024
52
-
53
- if GetFullPathNameA(path, buf.size, buf, nil) == 0
54
- raise SystemCallError.new('GetFullPathName', FFI.errno)
55
- end
56
-
57
- p buf.strip
58
- =end
59
-
60
- =begin
61
- ptr = FFI::MemoryPointer.from_string(path)
62
-
63
- p PathIsRelativeA(path)
64
-
65
- unless PathStripToRootA(ptr)
66
- raise SystemCallError.new('PathStripToRoot', FFI.errno)
67
- end
68
-
69
- p ptr.read_string
70
- =end
71
-
72
- =begin
73
- unless PathCanonicalizeA(buf, path)
74
- raise SystemCallError.new('PathCanonicalize', FFI.errno)
75
- end
76
-
77
- buf.strip
78
- =end
79
- end
80
- end
81
-
82
- if $0 == __FILE__
83
- Windows.new.xpath("/../../a", "foo")
84
- #p Windows.new.xpath("C:/foo/../bar")
85
- #p Windows.new.xpath("C:foo")
86
- #Windows.new.xpath("C:foo")
87
- #Windows.new.xpath("C:foo/bar")
88
- #Windows.new.xpath("C:/foo")
89
- #Windows.new.xpath("foo")
90
- end