@@ -19,10 +19,10 @@ fn is_relative(b: &[u8]) -> bool {
19
19
. position ( |& c| c == b'=' )
20
20
. map ( |x| x + 1 )
21
21
. unwrap_or ( 0 ) ;
22
- b. get ( pos) != Some ( & b'/' ) && !is_uri ( & b[ pos..] )
22
+ b. get ( pos) != Some ( & b'/' ) && !is_pseudo_url ( & b[ pos..] )
23
23
}
24
24
25
- /// Reference: https://github.com/NixOS/nix/blob/2.3.10 /src/libexpr/eval.cc#L242-L277
25
+ /// Reference: https://github.com/NixOS/nix/blob/2.23.0 /src/libexpr/eval-settings .cc#L9-L45
26
26
fn parse_nix_path ( s : & [ u8 ] ) -> Vec < & [ u8 ] > {
27
27
let mut res = Vec :: new ( ) ;
28
28
let mut p = 0 ;
@@ -45,7 +45,7 @@ fn parse_nix_path(s: &[u8]) -> Vec<&[u8]> {
45
45
}
46
46
47
47
if s[ p] == b':' {
48
- if is_uri ( & s[ start2..] ) {
48
+ if is_pseudo_url ( & s[ start2..] ) {
49
49
p += 1 ;
50
50
while p < s. len ( ) && s[ p] != b':' {
51
51
p += 1 ;
@@ -63,8 +63,8 @@ fn parse_nix_path(s: &[u8]) -> Vec<&[u8]> {
63
63
res
64
64
}
65
65
66
- /// Reference: https://github.com/NixOS/nix/blob/2.3.10 /src/libstore/download .cc#L936-L943
67
- pub fn is_uri ( s : & [ u8 ] ) -> bool {
66
+ /// Reference: https://github.com/NixOS/nix/blob/2.23.0 /src/libexpr/eval-settings .cc#L79-L86
67
+ pub fn is_pseudo_url ( s : & [ u8 ] ) -> bool {
68
68
let prefixes = & [
69
69
"channel:" ,
70
70
"http://" ,
@@ -74,6 +74,7 @@ pub fn is_uri(s: &[u8]) -> bool {
74
74
"git://" ,
75
75
"s3://" ,
76
76
"ssh://" ,
77
+ "flake:" , // Not in the original code
77
78
] ;
78
79
prefixes
79
80
. iter ( )
@@ -82,28 +83,41 @@ pub fn is_uri(s: &[u8]) -> bool {
82
83
83
84
#[ cfg( test) ]
84
85
mod tests {
85
- use super :: { is_relative, parse_nix_path} ;
86
+ use super :: * ;
87
+
86
88
macro_rules! v {
87
89
( $( $a: literal) ,* ) => { {
88
90
vec![ $( Vec :: <u8 >:: from( $a as & [ _] ) ) ,* ]
89
91
} }
90
92
}
93
+
91
94
#[ test]
92
- fn it_works ( ) {
95
+ fn test_parse_nix_path ( ) {
93
96
assert_eq ! ( parse_nix_path( b"foo:bar:baz" ) , v![ b"foo" , b"bar" , b"baz" ] ) ;
94
97
assert_eq ! (
95
98
parse_nix_path( b"foo:bar=something:baz" ) ,
96
99
v![ b"foo" , b"bar=something" , b"baz" ]
97
100
) ;
98
101
assert_eq ! (
99
- parse_nix_path( b"foo:bar=https://something:baz" ) ,
100
- v![ b"foo" , b"bar=https://something" , b"baz" ]
102
+ parse_nix_path(
103
+ b"foo:bar=https://something:baz=flake:something:qux"
104
+ ) ,
105
+ v![
106
+ b"foo" ,
107
+ b"bar=https://something" ,
108
+ b"baz=flake:something" ,
109
+ b"qux"
110
+ ]
101
111
) ;
112
+ }
102
113
114
+ #[ test]
115
+ fn test_is_relative ( ) {
103
116
assert ! ( is_relative( b"foo" ) ) ;
104
117
assert ! ( is_relative( b"foo=bar" ) ) ;
105
118
assert ! ( !is_relative( b"http://foo" ) ) ;
106
119
assert ! ( !is_relative( b"foo=/bar" ) ) ;
107
120
assert ! ( !is_relative( b"foo=http://bar" ) ) ;
121
+ assert ! ( !is_relative( b"foo=flake:bar" ) ) ;
108
122
}
109
123
}
0 commit comments