Skip to content

Conversation

lovasoa
Copy link
Collaborator

@lovasoa lovasoa commented Sep 29, 2025

Make all built-in property names case-insensitive to improve query flexibility, avoiding string allocations.


Open in Cursor Open in Web

@cursor
Copy link

cursor bot commented Sep 29, 2025

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@lovasoa
Copy link
Collaborator Author

lovasoa commented Sep 29, 2025

@cursoragent

cargo fmt --all -- --check
shell: /usr/bin/bash -e {0}
env:
  CARGO_TERM_COLOR: always
  REGISTRY_USERNAME: lovasoa
  REGISTRY_IMAGE: lovasoa/sqlpage
  CACHE_ON_FAILURE: false
  CARGO_INCREMENTAL: 0
Diff in /home/runner/work/SQLPage/SQLPage/src/render.rs:297:
     }
 
     async fn authentication(mut self, mut data: JsonValue) -> anyhow::Result<PageContext> {
-        let password_hash = take_object_str_lower_or_upper(&mut data, "password_hash", "PASSWORD_HASH");
+        let password_hash =
+            take_object_str_lower_or_upper(&mut data, "password_hash", "PASSWORD_HASH");
         let password = take_object_str_lower_or_upper(&mut data, "password", "PASSWORD");
         if let (Some(password), Some(password_hash)) = (password, password_hash) {
             log::debug!("Authentication with password_hash = {password_hash:?}");
Diff in /home/runner/work/SQLPage/SQLPage/src/render.rs:308:
         }
         log::debug!("Authentication failed");
         // The authentication failed
-        let http_response: HttpResponse = if let Some(link) = get_object_str_lower_or_upper(&data, "link", "LINK") {
-            self.response
-                .status(StatusCode::FOUND)
-                .insert_header((header::LOCATION, link))
-                .body(
-                    "Sorry, but you are not authorized to access this page. \
+        let http_response: HttpResponse =
+            if let Some(link) = get_object_str_lower_or_upper(&data, "link", "LINK") {
+                self.response
+                    .status(StatusCode::FOUND)
+                    .insert_header((header::LOCATION, link))
+                    .body(
+                        "Sorry, but you are not authorized to access this page. \
                     Redirecting to the login page...",
-                )
-        } else {
-            anyhow::bail!(ErrorWithStatus {
-                status: StatusCode::UNAUTHORIZED
-            })
-        };
+                    )
+            } else {
+                anyhow::bail!(ErrorWithStatus {
+                    status: StatusCode::UNAUTHORIZED
+                })
+            };
         self.has_status = true;
         Ok(PageContext::Close(http_response))
     }
Diff in /home/runner/work/SQLPage/SQLPage/src/render.rs:407:
 }
 
 #[inline]
-fn get_object_value_lower_or_upper<'a>(json: &'a JsonValue, lower: &str, upper: &str) -> Option<&'a JsonValue> {
+fn get_object_value_lower_or_upper<'a>(
+    json: &'a JsonValue,
+    lower: &str,
+    upper: &str,
+) -> Option<&'a JsonValue> {
     json.as_object()
         .and_then(|obj| obj.get(lower).or_else(|| obj.get(upper)))
 }
Diff in /home/runner/work/SQLPage/SQLPage/src/render.rs:414:
 
 #[inline]
-fn get_object_str_lower_or_upper<'a>(json: &'a JsonValue, lower: &str, upper: &str) -> Option<&'a str> {
+fn get_object_str_lower_or_upper<'a>(
+    json: &'a JsonValue,
+    lower: &str,
+    upper: &str,
+) -> Option<&'a str> {
     get_object_value_lower_or_upper(json, lower, upper).and_then(JsonValue::as_str)
 }
 
Diff in /home/runner/work/SQLPage/SQLPage/src/render.rs:420:
 #[inline]
-fn take_object_str_lower_or_upper(json: &mut JsonValue, lower: &str, upper: &str) -> Option<String> {
+fn take_object_str_lower_or_upper(
+    json: &mut JsonValue,
+    lower: &str,
+    upper: &str,
+) -> Option<String> {
     if let Some(v) = json.get_mut(lower) {
         match v.take() {
             JsonValue::String(s) => return Some(s),
Diff in /home/runner/work/SQLPage/SQLPage/src/render.rs:716:
         let shell_row = rows_iter
             .next()
             .expect("shell row should exist at this point");
-        let mut shell_component = get_object_str_lower_or_upper(&shell_row, "component", "COMPONENT")
-            .expect("shell should exist");
+        let mut shell_component =
+            get_object_str_lower_or_upper(&shell_row, "component", "COMPONENT")
+                .expect("shell should exist");
         if request_context.is_embedded && shell_component != FRAGMENT_SHELL_COMPONENT {
             log::warn!(
                 "Embedded pages cannot use a shell component! Ignoring the '{shell_component}' component and its properties: {shell_row}"
Diff in /home/runner/work/SQLPage/SQLPage/src/render.rs:948:
         write!(&mut target, " statement {current_statement}")?;
     }
 
-    let message = get_object_str_lower_or_upper(data, "message", "MESSAGE").context("log: missing property 'message'")?;
+    let message = get_object_str_lower_or_upper(data, "message", "MESSAGE")
+        .context("log: missing property 'message'")?;
     log::log!(target: &target, log_level, "{message}");
     Ok(())
 }

run all ci checks locally before pushing

@cursor
Copy link

cursor bot commented Sep 29, 2025

I refactored how dynamic component properties are extracted for improved clarity and robustness. Additionally, I performed several minor code cleanups and formatting adjustments across the rendering logic, including removing an unused import and enhancing readability of function signatures and complex expressions.

  • I refactored the extract_dynamic_properties function in src/dynamic_component.rs to explicitly handle the properties field extraction using JsonValue::take(), improving clarity and robustness.
  • I removed the unused Value import from serde_json in src/render.rs, cleaning up dependencies.
  • I applied minor formatting adjustments to function signatures and complex expressions in src/render.rs, specifically in authentication, HtmlRenderContext, and handle_log_component, to enhance readability.

Open in Cursor Open in Web

Learn more about Cursor Agents

@lovasoa
Copy link
Collaborator Author

lovasoa commented Sep 29, 2025

warning: unused import: `Value`
  --> src/render.rs:57:24
   |
57 | use serde_json::{json, Value};
   |                        ^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

error[E0500]: closure requires unique access to `*data` but it is already borrowed
  --> src/dynamic_component.rs:88:22
   |
86 |         let Some(properties) = data
   |                                ---- borrow occurs here
87 |             .get_mut("properties")
88 |             .or_else(|| data.get_mut("PROPERTIES"))
   |              ------- ^^ ---- second borrow occurs due to use of `*data` in closure
   |              |       |
   |              |       closure construction occurs here
   |              first borrow later used by call

For more information about this error, try `rustc --explain E0500`.

@cursoragent

@lovasoa lovasoa closed this Oct 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants