Skip to content

Commit 6babba1

Browse files
authored
Merge branch 'main' into better_run_sql_management
2 parents 0e2ca42 + 6c68d1d commit 6babba1

File tree

5 files changed

+29
-13
lines changed

5 files changed

+29
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- New `search_value` property in the shell component.
88
- Fixed a display issue in the hero component when the button text is long and the viewport is narrow.
99
- reuse the existing opened database connection for the current query in `sqlpage.run_sql` instead of opening a new one. This makes it possible to create a temporary table in a file, and reuse it in an included script, create a SQL transaction that spans over multiple run_sql calls, and should generally make run_sql more performant.
10+
- Fixed a bug in the cookie component where removing a cookie from a subdirectory would not work.
1011

1112
## 0.22.0 (2024-05-29)
1213
- **Important Security Fix:** The behavior of `SET $x` has been modified to match `SELECT $x`.

examples/image gallery with user uploads/login.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ select 'text' as type, 'Username' as name, true as required;
55
select 'password' as type, 'Password' as name, true as required;
66

77

8-
select 'alert' as component, 'You are not logged in' as title,
9-
'Sorry, we could not log you in. Please try again.' as description
8+
select 'alert' as component,
9+
'danger' as color,
10+
'You are not logged in' as title,
11+
'Sorry, we could not log you in. Please try again.' as description
1012
where $error is not null;

examples/read-and-set-http-cookies/index.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ SELECT 'username' as name,
1111
'try leaving this page and coming back, the value should be saved in a cookie' as description;
1212

1313
select 'text' as component;
14-
select 'log out' as contents, 'logout.sql' as link;
14+
select 'log out' as contents, 'logout.sql' as link;
15+
16+
select 'text' as component;
17+
select 'View the cookie from a subdirectory' as contents, 'subdirectory/read_cookies.sql' as link;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- Cookies can be specific to a certain path in the website
2+
-- This page demonstrates that a gobal cookie can be removed from a subdirectory
3+
select 'cookie' as component, 'username' as name, true as remove, '/' as path;
4+
5+
SELECT 'text' as component;
6+
SELECT 'The value of your username cookie was: ' ||
7+
COALESCE(sqlpage.cookie('username'), 'NULL') ||
8+
'. It has now been removed. You can reload this page.' as contents;
9+

src/render.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,17 @@ impl<'a, W: std::io::Write> HeaderContext<'a, W> {
114114
.with_context(|| "cookie name must be a string")?;
115115
let mut cookie = actix_web::cookie::Cookie::named(name);
116116

117+
let path = obj.get("path").and_then(JsonValue::as_str);
118+
if let Some(path) = path {
119+
cookie.set_path(path);
120+
} else {
121+
cookie.set_path("/");
122+
}
123+
let domain = obj.get("domain").and_then(JsonValue::as_str);
124+
if let Some(domain) = domain {
125+
cookie.set_domain(domain);
126+
}
127+
117128
let remove = obj.get("remove");
118129
if remove == Some(&json!(true)) || remove == Some(&json!(1)) {
119130
cookie.make_removal();
@@ -138,16 +149,6 @@ impl<'a, W: std::io::Write> HeaderContext<'a, W> {
138149
});
139150
let secure = obj.get("secure");
140151
cookie.set_secure(secure != Some(&json!(false)) && secure != Some(&json!(0)));
141-
let path = obj.get("path").and_then(JsonValue::as_str);
142-
if let Some(path) = path {
143-
cookie.set_path(path);
144-
} else {
145-
cookie.set_path("/");
146-
}
147-
let domain = obj.get("domain").and_then(JsonValue::as_str);
148-
if let Some(domain) = domain {
149-
cookie.set_domain(domain);
150-
}
151152
let expires = obj.get("expires");
152153
if let Some(expires) = expires {
153154
cookie.set_expires(actix_web::cookie::Expiration::DateTime(match expires {

0 commit comments

Comments
 (0)