Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
mf
go-multiaddr
Commits
d31f3765
Unverified
Commit
d31f3765
authored
Jun 12, 2024
by
Marco Munizaga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PR comments
parent
e0315b98
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
1 deletion
+30
-1
multiaddr_test.go
multiaddr_test.go
+18
-1
transcoders.go
transcoders.go
+12
-0
No files found.
multiaddr_test.go
View file @
d31f3765
...
@@ -192,6 +192,11 @@ var good = []string{
...
@@ -192,6 +192,11 @@ var good = []string{
"/ip4/127.0.0.1/tcp/127/wss"
,
"/ip4/127.0.0.1/tcp/127/wss"
,
"/ip4/127.0.0.1/tcp/127/webrtc-direct"
,
"/ip4/127.0.0.1/tcp/127/webrtc-direct"
,
"/ip4/127.0.0.1/tcp/127/webrtc"
,
"/ip4/127.0.0.1/tcp/127/webrtc"
,
"/http-path/tmp%2Fbar"
,
"/http-path/tmp%2Fbar%2Fbaz"
,
"/http-path/foo"
,
"/ip4/127.0.0.1/tcp/0/p2p/12D3KooWCryG7Mon9orvQxcS1rYZjotPgpwoJNHHKcLLfE4Hf5mV/http-path/foo"
,
"/ip4/127.0.0.1/tcp/443/tls/sni/example.com/http/http-path/foo"
,
}
}
func
TestConstructSucceeds
(
t
*
testing
.
T
)
{
func
TestConstructSucceeds
(
t
*
testing
.
T
)
{
...
@@ -927,16 +932,28 @@ func TestDNS(t *testing.T) {
...
@@ -927,16 +932,28 @@ func TestDNS(t *testing.T) {
func
TestHTTPPath
(
t
*
testing
.
T
)
{
func
TestHTTPPath
(
t
*
testing
.
T
)
{
t
.
Run
(
"bad addr"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"bad addr"
,
func
(
t
*
testing
.
T
)
{
badAddr
:=
"/http-path/thisIsMissingAfullByte
s
%f"
badAddr
:=
"/http-path/thisIsMissingAfullByte%f"
_
,
err
:=
NewMultiaddr
(
badAddr
)
_
,
err
:=
NewMultiaddr
(
badAddr
)
require
.
Error
(
t
,
err
)
require
.
Error
(
t
,
err
)
})
})
t
.
Run
(
"only reads the http-path part"
,
func
(
t
*
testing
.
T
)
{
addr
:=
"/http-path/tmp%2Fbar/p2p-circuit"
// The http-path only reference the part immediately after it. It does not include the rest of the multiaddr (like the /path component sometimes does)
m
,
err
:=
NewMultiaddr
(
addr
)
require
.
NoError
(
t
,
err
)
m
.
ValueForProtocol
(
P_HTTP_PATH
)
v
,
err
:=
m
.
ValueForProtocol
(
P_HTTP_PATH
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
"tmp%2Fbar"
,
v
)
})
t
.
Run
(
"round trip"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"round trip"
,
func
(
t
*
testing
.
T
)
{
cases
:=
[]
string
{
cases
:=
[]
string
{
"/http-path/tmp%2Fbar"
,
"/http-path/tmp%2Fbar"
,
"/http-path/tmp%2Fbar%2Fbaz"
,
"/http-path/tmp%2Fbar%2Fbaz"
,
"/http-path/foo"
,
"/http-path/foo"
,
"/ip4/127.0.0.1/tcp/0/p2p/12D3KooWCryG7Mon9orvQxcS1rYZjotPgpwoJNHHKcLLfE4Hf5mV/http-path/foo"
,
"/ip4/127.0.0.1/tcp/443/tls/sni/example.com/http/http-path/foo"
,
}
}
for
_
,
c
:=
range
cases
{
for
_
,
c
:=
range
cases
{
m
,
err
:=
NewMultiaddr
(
c
)
m
,
err
:=
NewMultiaddr
(
c
)
...
...
transcoders.go
View file @
d31f3765
...
@@ -460,13 +460,25 @@ var TranscoderHTTPPath = NewTranscoderFromFunctions(httpPathStB, httpPathBtS, va
...
@@ -460,13 +460,25 @@ var TranscoderHTTPPath = NewTranscoderFromFunctions(httpPathStB, httpPathBtS, va
func
httpPathStB
(
s
string
)
([]
byte
,
error
)
{
func
httpPathStB
(
s
string
)
([]
byte
,
error
)
{
unescaped
,
err
:=
url
.
QueryUnescape
(
s
)
unescaped
,
err
:=
url
.
QueryUnescape
(
s
)
if
err
!=
nil
{
return
nil
,
err
}
if
len
(
unescaped
)
==
0
{
return
nil
,
fmt
.
Errorf
(
"empty http path is not allowed"
)
}
return
[]
byte
(
unescaped
),
err
return
[]
byte
(
unescaped
),
err
}
}
func
httpPathBtS
(
b
[]
byte
)
(
string
,
error
)
{
func
httpPathBtS
(
b
[]
byte
)
(
string
,
error
)
{
if
len
(
b
)
==
0
{
return
""
,
fmt
.
Errorf
(
"empty http path is not allowed"
)
}
return
url
.
QueryEscape
(
string
(
b
)),
nil
return
url
.
QueryEscape
(
string
(
b
)),
nil
}
}
func
validateHTTPPath
(
b
[]
byte
)
error
{
func
validateHTTPPath
(
b
[]
byte
)
error
{
if
len
(
b
)
==
0
{
return
fmt
.
Errorf
(
"empty http path is not allowed"
)
}
return
nil
// We can represent any byte slice when we escape it.
return
nil
// We can represent any byte slice when we escape it.
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment