Skip to content

Commit c8cb5cd

Browse files
makenowjustysbaddaden
authored andcommittedAug 1, 2017
Don't find in CRYSTAL_PATH if required path is relative (#4765)
Don't search in CRYSTAL_PATH if required path is relative closes #4742
1 parent 8f2f505 commit c8cb5cd

File tree

17 files changed

+33
-24
lines changed

17 files changed

+33
-24
lines changed
 

‎spec/compiler/crystal_path/crystal_path_spec.cr

+5
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,9 @@ describe Crystal::CrystalPath do
9090
assert_doesnt_find "test_folder/*", relative_to: "#{__DIR__}/test_files/file_one.cr"
9191
assert_doesnt_find "test_files/missing_file.cr"
9292
assert_doesnt_find __FILE__[1..-1], path: ":"
93+
94+
# Don't find in CRYSTAL_PATH if the path is relative (#4742)
95+
assert_doesnt_find "./crystal_path_spec", relative_to: "test_files/file_one.cr"
96+
assert_doesnt_find "./crystal_path_spec.cr", relative_to: "test_files/file_one.cr"
97+
assert_doesnt_find "../crystal_path/test_files/file_one"
9398
end

‎spec/std/openssl/digest_io_spec.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require "spec"
2-
require "../src/openssl"
2+
require "../../../src/openssl"
33

44
describe OpenSSL::DigestIO do
55
it "calculates digest from reading" do

‎spec/std/openssl/digest_spec.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require "spec"
2-
require "../src/openssl"
2+
require "../../../src/openssl"
33

44
describe OpenSSL::Digest do
55
[

‎src/big/big_float.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require "c/string"
2-
require "./big"
2+
require "big"
33

44
# A `BigFloat` can represent arbitrarily large floats.
55
#

‎src/big/big_int.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require "c/string"
2-
require "./big"
2+
require "big"
33

44
# A `BigInt` can represent arbitrarily large integers.
55
#

‎src/big/big_rational.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require "./big"
1+
require "big"
22

33
# Rational numbers are represented as the quotient of arbitrarily large
44
# numerators and denominators. Rationals are canonicalized such that the

‎src/big/json.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require "json"
2-
require "./big"
2+
require "big"
33

44
def BigInt.new(pull : JSON::PullParser)
55
pull.read_int

‎src/big/yaml.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require "yaml"
2-
require "./big"
2+
require "big"
33

44
def BigInt.new(pull : YAML::PullParser)
55
BigInt.new(pull.read_scalar)

‎src/compiler/crystal/crystal_path.cr

+13-9
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,20 @@ module Crystal
5050

5151
def find(filename, relative_to = nil) : Array(String)?
5252
relative_to = File.dirname(relative_to) if relative_to.is_a?(String)
53+
5354
if filename.starts_with? '.'
5455
result = find_in_path_relative_to_dir(filename, relative_to)
5556
else
56-
result = find_in_crystal_path(filename, relative_to)
57+
result = find_in_crystal_path(filename)
5758
end
59+
60+
cant_find_file filename, relative_to unless result
61+
5862
result = [result] if result.is_a?(String)
5963
result
6064
end
6165

62-
private def find_in_path_relative_to_dir(filename, relative_to, check_crystal_path = true)
66+
private def find_in_path_relative_to_dir(filename, relative_to)
6367
if relative_to.is_a?(String)
6468
# Check if it's a wildcard.
6569
if filename.ends_with?("/*") || (recursive = filename.ends_with?("/**"))
@@ -116,11 +120,7 @@ module Crystal
116120
end
117121
end
118122

119-
if check_crystal_path
120-
find_in_crystal_path filename, relative_to
121-
else
122-
nil
123-
end
123+
nil
124124
end
125125

126126
private def gather_dir_files(dir, files_accumulator, recursive)
@@ -158,12 +158,16 @@ module Crystal
158158
File.expand_path(filename)
159159
end
160160

161-
private def find_in_crystal_path(filename, relative_to)
161+
private def find_in_crystal_path(filename)
162162
@crystal_path.each do |path|
163-
required = find_in_path_relative_to_dir(filename, path, check_crystal_path: false)
163+
required = find_in_path_relative_to_dir(filename, path)
164164
return required if required
165165
end
166166

167+
nil
168+
end
169+
170+
private def cant_find_file(filename, relative_to)
167171
if relative_to
168172
raise Error.new("can't find file '#{filename}' relative to '#{relative_to}'")
169173
else

‎src/csv/builder.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require "./csv"
1+
require "csv"
22

33
# A CSV Builder writes CSV to an `IO`.
44
#

‎src/csv/error.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require "./csv"
1+
require "csv"
22

33
class CSV
44
# Raises when an error related to a CSV is found.

‎src/csv/lexer.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require "./csv"
1+
require "csv"
22

33
# A CSV lexer lets you consume a CSV token by token. You can use this to efficiently
44
# parse a CSV without the need to allocate intermediate arrays.

‎src/csv/parser.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require "./csv"
1+
require "csv"
22

33
# A CSV parser. It lets you consume a CSV row by row.
44
#

‎src/csv/token.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require "./csv"
1+
require "csv"
22

33
# A token in a CSV. It consists of a `Kind` and a value.
44
# The value only makes sense when the *kind* is `Cell`.

‎src/ecr/processor.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require "./ecr/lexer"
1+
require "./lexer"
22

33
module ECR
44
extend self

‎src/openssl/cipher.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require "./openssl"
1+
require "openssl"
22

33
class OpenSSL::Cipher
44
class Error < OpenSSL::Error

‎src/openssl/pkcs5.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require "./openssl"
1+
require "openssl"
22

33
module OpenSSL::PKCS5
44
def self.pbkdf2_hmac_sha1(secret, salt, iterations = 2**16, key_size = 64) : Bytes

0 commit comments

Comments
 (0)
Please sign in to comment.