Skip to content

Commit 7ea28e2

Browse files
committed
allow setting a url fragment in sqlpage.link
1 parent 7fcfd19 commit 7ea28e2

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/webserver/database/sqlpage_functions/functions.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ super::function_definition_macro::sqlpage_functions! {
2727
hash_password(password: Option<String>);
2828
header((&RequestInfo), name: Cow<str>);
2929

30-
link(file: Cow<str>, parameters: Cow<str>);
30+
link(file: Cow<str>, parameters: Option<Cow<str>>, hash: Option<Cow<str>>);
3131

3232
path((&RequestInfo));
3333
persist_uploaded_file((&RequestInfo), field_name: Cow<str>, folder: Option<Cow<str>>, allowed_extensions: Option<Cow<str>>);
@@ -197,13 +197,21 @@ async fn header<'a>(request: &'a RequestInfo, name: Cow<'a, str>) -> Option<Cow<
197197
/// Builds a URL from a file name and a JSON object conatining URL parameters.
198198
/// For instance, if the file is "index.sql" and the parameters are {"x": "hello world"},
199199
/// the result will be "index.sql?x=hello%20world".
200-
async fn link<'a>(file: Cow<'a, str>, parameters: Option<Cow<'a, str>>) -> anyhow::Result<String> {
200+
async fn link<'a>(
201+
file: Cow<'a, str>,
202+
parameters: Option<Cow<'a, str>>,
203+
hash: Option<Cow<'a, str>>,
204+
) -> anyhow::Result<String> {
201205
let mut url = file.into_owned();
202206
if let Some(parameters) = parameters {
203207
url.push('?');
204208
let encoded = serde_json::from_str::<URLParameters>(&parameters)?;
205209
url.push_str(encoded.get());
206210
}
211+
if let Some(hash) = hash {
212+
url.push('#');
213+
url.push_str(&hash);
214+
}
207215
Ok(url)
208216
}
209217

0 commit comments

Comments
 (0)