@@ -370,13 +370,14 @@ impl ViewerOpenUrl {
370
370
// Combine the URL(s) with the web viewer base URL if provided.
371
371
if let Some ( web_viewer_base_url) = web_viewer_base_url {
372
372
let mut share_url = web_viewer_base_url. clone ( ) ;
373
- share_url. set_query ( Some (
374
- & urls
375
- . into_iter ( )
376
- . map ( |url| format ! ( "url={url}" ) )
377
- . collect :: < Vec < _ > > ( )
378
- . join ( "&" ) ,
379
- ) ) ;
373
+
374
+ // Use the form_urlencoded::Serializer to build the query string with multiple "url" parameters.
375
+ // It's important to not just append the strings, since we have to take care of correctly escaping.
376
+ let mut serializer = url:: form_urlencoded:: Serializer :: new ( String :: new ( ) ) ;
377
+ for url in & urls {
378
+ serializer. append_pair ( "url" , url) ;
379
+ }
380
+ share_url. set_query ( Some ( & serializer. finish ( ) ) ) ;
380
381
381
382
Ok ( share_url. to_string ( ) )
382
383
} else if urls. len ( ) == 1 {
@@ -978,60 +979,58 @@ mod tests {
978
979
ViewerOpenUrl :: IntraRecordingSelection ( "my/path" . parse( ) . unwrap( ) )
979
980
. sharable_url( base_url_param)
980
981
. unwrap( ) ,
981
- "https://foo.com/test?url=recording://my/path"
982
- ) ;
983
-
984
- assert_eq ! (
985
- ViewerOpenUrl :: RrdHttpUrl ( Url :: parse( "https://example.com/data.rrd" ) . unwrap( ) )
986
- . sharable_url( base_url_param)
987
- . unwrap( ) ,
988
- "https://foo.com/test?url=https://example.com/data.rrd"
982
+ "https://foo.com/test?url=recording%3A%2F%2Fmy%2Fpath"
989
983
) ;
990
984
991
985
assert_eq ! (
992
- ViewerOpenUrl :: FilePath ( "/path/to/file .rrd". into ( ) )
986
+ ViewerOpenUrl :: RrdHttpUrl ( "https://example.com/data .rrd". parse ( ) . unwrap ( ) )
993
987
. sharable_url( base_url_param)
994
988
. unwrap( ) ,
995
- "https://foo.com/test?url=/path/to/file .rrd"
989
+ "https://foo.com/test?url=https%3A%2F%2Fexample.com%2Fdata .rrd"
996
990
) ;
997
991
998
- let uri =
999
- "rerun://127.0.0.1:1234/dataset/1830B33B45B963E7774455beb91701ae?partition_id=pid" ;
1000
992
assert_eq ! (
1001
- ViewerOpenUrl :: RedapDatasetPartition ( uri. parse( ) . unwrap( ) )
1002
- . sharable_url( base_url_param)
1003
- . unwrap( ) ,
1004
- format!( "https://foo.com/test?url={uri}" )
993
+ ViewerOpenUrl :: RedapDatasetPartition (
994
+ "rerun://127.0.0.1:1234/dataset/1830B33B45B963E7774455beb91701ae?partition_id=pid"
995
+ . parse( )
996
+ . unwrap( )
997
+ )
998
+ . sharable_url( base_url_param)
999
+ . unwrap( ) ,
1000
+ format!(
1001
+ "https://foo.com/test?url=rerun%3A%2F%2F127.0.0.1%3A1234%2Fdataset%2F1830B33B45B963E7774455beb91701ae%3Fpartition_id%3Dpid"
1002
+ )
1005
1003
) ;
1006
1004
1007
1005
assert_eq ! (
1008
1006
ViewerOpenUrl :: RedapProxy ( "rerun://localhost:51234/proxy" . parse( ) . unwrap( ) )
1009
1007
. sharable_url( base_url_param)
1010
1008
. unwrap( ) ,
1011
- "https://foo.com/test?url=rerun://localhost:51234/proxy "
1009
+ "https://foo.com/test?url=rerun%3A%2F%2Flocalhost%3A51234%2Fproxy "
1012
1010
) ;
1013
1011
1014
1012
assert_eq ! (
1015
1013
ViewerOpenUrl :: RedapCatalog ( "rerun://localhost:51234/catalog" . parse( ) . unwrap( ) )
1016
1014
. sharable_url( base_url_param)
1017
1015
. unwrap( ) ,
1018
- "https://foo.com/test?url=rerun://localhost:51234/catalog "
1016
+ "https://foo.com/test?url=rerun%3A%2F%2Flocalhost%3A51234%2Fcatalog "
1019
1017
) ;
1020
1018
1021
1019
let entry_id = EntryId :: new ( ) ;
1022
1020
let url = format ! ( "rerun://localhost:51234/entry/{entry_id}" ) ;
1021
+ let encoded_url = url:: form_urlencoded:: byte_serialize ( url. as_bytes ( ) ) . collect :: < String > ( ) ;
1023
1022
assert_eq ! (
1024
1023
ViewerOpenUrl :: RedapEntry ( url. parse( ) . unwrap( ) )
1025
1024
. sharable_url( base_url_param)
1026
1025
. unwrap( ) ,
1027
- format!( "https://foo.com/test?url={url }" )
1026
+ format!( "https://foo.com/test?url={encoded_url }" )
1028
1027
) ;
1029
1028
1030
1029
assert_eq ! (
1031
1030
ViewerOpenUrl :: WebEventListener
1032
1031
. sharable_url( base_url_param)
1033
1032
. unwrap( ) ,
1034
- "https://foo.com/test?url=web_event: "
1033
+ "https://foo.com/test?url=web_event%3A "
1035
1034
) ;
1036
1035
1037
1036
assert_eq ! (
@@ -1043,7 +1042,7 @@ mod tests {
1043
1042
}
1044
1043
. sharable_url( base_url_param)
1045
1044
. unwrap( ) ,
1046
- "https://foo.com/test?url=https://example .com/data .rrd" ,
1045
+ "https://foo.com/test?url=https%3A%2F%2Fexample .com%2Fdata .rrd" ,
1047
1046
) ;
1048
1047
assert_eq ! (
1049
1048
ViewerOpenUrl :: WebViewerUrl {
@@ -1055,7 +1054,7 @@ mod tests {
1055
1054
}
1056
1055
. sharable_url( base_url_param)
1057
1056
. unwrap( ) ,
1058
- "https://foo.com/test?url=https://example .com/bar .rrd&url=rerun://localhost:51234/proxy " ,
1057
+ "https://foo.com/test?url=https%3A%2F%2Fexample .com%2Fbar .rrd&url=rerun%3A%2F%2Flocalhost%3A51234%2Fproxy " ,
1059
1058
) ;
1060
1059
}
1061
1060
}
0 commit comments