diff --git a/CHANGELOG.md b/CHANGELOG.md index d5bf6cdb..ddca3ec8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,11 @@ - updated the SQL parser to [v0.48](https://github.com/sqlparser-rs/sqlparser-rs/blob/main/CHANGELOG.md#0480-2024-07-09) - upport UPDATE statements that contain tuple assignments , like `UPDATE table SET (a, b) = (SELECT 1, 2)` - support custom operators in postgres. Usefull when using extensions like PostGIS, PGroonga, pgtrgm, or pg_similarity, which define custom operators like `&&&`, `@>`, `<->`, `~>`, `~>=`, `~<=`, `<@`... + - New `html` component to display raw HTML content. This component is meant to be used by advanced users who want to display HTML content that cannot be expressed with the other components. Make sure you understand the security implications before using this component, as using untrusted HTML content can expose your users to [cross-site scripting (XSS)](https://en.wikipedia.org/wiki/Cross-site_scripting) attacks. + - New parameter in the [`run_sql`](https://sql.ophir.dev/functions.sql?function=run_sql#function) function to pass variables to the included SQL file, instead of using the global variables. Together with the new ability to pass data from the database to SQLPage functions, this allows you to create more modular and reusable SQL files. For instance, the following is finally possible: + ```sql + select 'dynamic' as component, sqlpage.run_sql('display_product.sql', json_object('product_id', product_id)) as properties from products; + ``` ## 0.24.0 (2024-06-23) - in the form component, searchable `select` fields now support more than 50 options. They used to display only the first 50 options. diff --git a/examples/official-site/sqlpage/migrations/38_run_sql.sql b/examples/official-site/sqlpage/migrations/38_run_sql.sql index cf4143fe..e8464030 100644 --- a/examples/official-site/sqlpage/migrations/38_run_sql.sql +++ b/examples/official-site/sqlpage/migrations/38_run_sql.sql @@ -47,4 +47,10 @@ VALUES ( 'Path to the SQL file to execute, can be absolute, or relative to the web root (the root folder of your website sql files). In-database files, from the sqlpage_files(path, contents, last_modified) table are supported.', 'TEXT' + ),( + 'run_sql', + 2, + 'parameters', + 'Optional JSON object to pass as parameters to the included SQL file. The keys of the object will be available as variables in the included file. By default, the included file will have access to the same variables as the calling file.', + 'JSON' ); diff --git a/examples/official-site/sqlpage/migrations/46_html.sql b/examples/official-site/sqlpage/migrations/46_html.sql new file mode 100644 index 00000000..c34dedec --- /dev/null +++ b/examples/official-site/sqlpage/migrations/46_html.sql @@ -0,0 +1,45 @@ +-- Documentation for the RSS component +INSERT INTO component (name, description, icon, introduced_in_version) VALUES ( + 'html', + 'Include raw HTML in the output. For advanced users only. Use this component to create complex layouts or to include external content. + Be very careful when using this component with user-generated content, as it can lead to security vulnerabilities. + Use this component only if you are familiar with the security implications of including raw HTML, and understand the risks of cross-site scripting (XSS) attacks.', + 'html', + '0.25.0' +); + +INSERT INTO parameter (component,name,description,type,top_level,optional) VALUES ( + 'html', + 'html', + 'Raw HTML content to include in the page. This will not be sanitized or escaped. If you include content from an untrusted source, your page will be vulnerable to cross-site scripting attacks.', + 'TEXT', + TRUE, + TRUE +),( + 'html', + 'html', + 'Raw HTML content to include in the page. This will not be sanitized or escaped. If you include content from an untrusted source, your page will be vulnerable to cross-site scripting attacks.', + 'TEXT', + FALSE, + TRUE +); + +-- Insert example(s) for the component +INSERT INTO example (component, description, properties) VALUES ( + 'html', + 'Include a simple HTML snippet. In this example, the HTML code is hardcoded in the SQL query, so it is safe. You should never include data that may be manipulated by a user in the HTML content. + ', + JSON('[{ + "component": "html", + "html": "