-
-
Notifications
You must be signed in to change notification settings - Fork 184
Add optional fontSize, width, and height parameters for SVG customization (Fixes #334) #357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,43 @@ | ||
| const getTemplate = (template) => { | ||
| const escapeHtml = require('escape-html'); | ||
| const safeUrl = escapeHtml(template.bgImage); | ||
| const backgroundImageLayer = safeUrl | ||
| ? `<image href="${safeUrl}" | ||
| const escapeHtml = require('escape-html'); | ||
|
|
||
|
|
||
| const svgWidth = Number.isFinite(template.width) ? template.width : 700; | ||
| const svgHeight = Number.isFinite(template.height) ? template.height : 200; | ||
| const textFontSize = Number.isFinite(template.fontSize) ? template.fontSize : 16; | ||
|
|
||
| const safeUrl = escapeHtml(template.bgImage); | ||
| const backgroundImageLayer = safeUrl | ||
| ? `<image href="${safeUrl}" | ||
| x="0" y="0" | ||
| width="700" | ||
| height="${parseInt(template.height)}" | ||
| width="${svgWidth}" | ||
| height="${svgHeight}" | ||
| preserveAspectRatio="xMidYMid slice" />` | ||
| : ''; | ||
| : ''; | ||
|
|
||
| return ` | ||
| <svg width="700px" height="${parseInt( | ||
| template.height | ||
| )}px" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
| <defs> | ||
| <style> | ||
| @font-face{ | ||
| font-family: "customFont"; | ||
| src: ${template.font.src} | ||
| } | ||
| </style> | ||
| </defs> | ||
| ${backgroundImageLayer} | ||
| <foreignObject width="100%" height="100%"> | ||
| <div xmlns="http://www.w3.org/1999/xhtml"> | ||
| <style> | ||
| ${template.css} | ||
| </style> | ||
| ${template.structure} | ||
| </div> | ||
| </foreignObject> | ||
| return ` | ||
| <svg width="${svgWidth}px" height="${svgHeight}px" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
| <defs> | ||
| <style> | ||
| @font-face{ | ||
| font-family: "customFont"; | ||
| src: ${template.font.src} | ||
| } | ||
|
|
||
| .quote-text { | ||
| font-size: ${textFontSize}px !important; | ||
| } | ||
|
Comment on lines
+27
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainVerify that The new CSS rule applies Run the following script to verify that the 🏁 Script executed: #!/bin/bash
# Search for 'quote-text' class usage in layout files
rg -n --type=js 'quote-text' src/layouts/ src/models/Length of output: 0 🏁 Script executed: #!/bin/bash
# Broad search for 'quote-text' usage across all source files
rg -n 'quote-text' src/Length of output: 50 Ensure 🤖 Prompt for AI Agents |
||
| </style> | ||
| </defs> | ||
| ${backgroundImageLayer} | ||
| <foreignObject width="100%" height="100%"> | ||
| <div xmlns="http://www.w3.org/1999/xhtml"> | ||
| <style> | ||
| ${template.css} | ||
| </style> | ||
| ${template.structure} | ||
| </div> | ||
| </foreignObject> | ||
| </svg>`; | ||
|
Comment on lines
+18
to
41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainVerify sanitization of While Run the following script to trace the sources of If these properties incorporate user input without sanitization, apply 🏁 Script executed: #!/bin/bash
# Find where template.css and template.structure are set
rg -n --type=js 'template\.css\s*=' src/
rg -n --type=js 'template\.structure\s*=' src/
rg -n --type=js '\.setTheme\(' src/
rg -n --type=js '\.setLayout\(' src/Length of output: 135 🏁 Script executed: #!/bin/bash
# Show definitions of setTheme and setLayout with context
rg -nC5 "setTheme" src/
rg -nC5 "setLayout" src/Length of output: 2747 🏁 Script executed: #!/bin/bash
# Show definitions of setStyle and setStructure with context
rg -nC5 "setStyle" src/models/Template.js
rg -nC5 "setStructure" src/models/Template.jsLength of output: 940 🏁 Script executed: #!/bin/bash
# Show quotesService.js with context
sed -n '1,200p' src/api/services/quotesService.jsLength of output: 3622 🏁 Script executed: #!/bin/bash
# Inspect generateTemplate implementation and layout definitions
sed -n '1,200p' src/utils/generateTemplate.jsLength of output: 293 Sanitize layout CSS and HTML structure before injection In src/common/getTemplate.js, you’re inserting <style>
- ${template.css}
+ ${escapeHtml(template.css)}
</style>
…
- ${template.structure}
+ ${escapeHtml(template.structure)}
🤖 Prompt for AI Agents |
||
| }; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Enhance input validation in the
toNumhelper.The current implementation has several gaps:
Allows
Infinityand-Infinity: These pass the!Number.isNaN(Number(v))check but are rejected later byNumber.isFinitein the service layer. Validation should be consolidated.Allows negative and zero values: Negative dimensions (
width=-100) and zero dimensions (fontSize=0) are nonsensical but aren't rejected.Redundant conversion:
Number(v)is called twice—once for the NaN check and once for the return value.Apply this diff to add comprehensive validation:
This consolidates validation, removes redundant conversions, and ensures only positive finite numbers are accepted. You may also want to add upper bounds (e.g.,
num > 0 && num <= 2000).📝 Committable suggestion
🤖 Prompt for AI Agents