8000
| if ("order".equals(id)) { | ||
| continue; | ||
| } | ||
| builders.put(id, ThemeRe 8000 sourceDescriptor.builder(properties.getProperty(key))); | ||
| } |
| public boolean hasDefer() { | ||
| return defer != null && isTruthy(defer); | ||
| } | ||
|
|
||
| public boolean hasAsync() { | ||
| return async != null && isTruthy(async); | ||
| } | ||
|
|
||
| public boolean hasType() { | ||
| return type != null && !type.isEmpty(); | ||
| } | ||
|
|
||
| public boolean hasBlocking() { | ||
| return blocking != null && !blocking.isEmpty(); | ||
| } | ||
|
|
||
| public boolean hasRel() { | ||
| return rel != null && !rel.isEmpty(); | ||
| } | ||
|
|
||
| private static boolean isTruthy(String value) { | ||
| return "true".equalsIgnoreCase(value) || "defer".equalsIgnoreCase(value) || "async".equalsIgnoreCase(value); | ||
| } |
|
|
||
| <#macro renderScripts resources pathPrefix defaultScriptType=""> | ||
| <#list resources as resource> | ||
| <script src="${pathPrefix}/${resource.path}"<#if resource.type?has_content> type="${resource.type}"<#elseif defaultScriptType?has_content> type="${defaultScriptType}"</#if><#if resource.media?has_content> media="${resource.media}"</#if><#if resource.integrity?has_content> integrity="${resource.integrity}"</#if><#if resource.crossorigin?has_content> crossorigin="${resource.crossorigin}"</#if><#if resource.hasDefer> defer</#if><#if resource.hasAsync> async</#if><#if resource.blocking?has_content> blocking="${resource.blocking}"</#if>></script> |
|
|
||
| <#macro renderScripts resources pathPrefix defaultScriptType=""> | ||
| <#list resources as resource> | ||
| <script src="${pathPrefix}/${resource.path}"<#if resource.type?has_content> type="${resource.type}"<#elseif defaultScriptType?has_content> type="${defaultScriptType}"</#if><#if resource.media?has_content> media="${resource.media}"</#if><#if resource.integrity?has_content> integrity="${resource.integrity}"</#if><#if resource.crossorigin?has_content> crossorigin="${resource.crossorigin}"</#if><#if resource.hasDefer> defer</#if><#if resource.hasAsync> async</#if><#if resource.blocking?has_content> blocking="${resource.blocking}"</#if>></script> |
|
|
||
| <#macro renderScripts resources pathPrefix defaultScriptType=""> | ||
| <#list resources as resource> | ||
| <script src="${pathPrefix}/${resource.path}"<#if resource.type?has_content> type="${resource.type}"<#elseif defaultScriptType?has_content> type="${defaultScriptType}"</#if><#if resource.media?has_content> media="${resource.media}"</#if><#if resource.integrity?has_content> integrity="${resource.integrity}"</#if><#if resource.crossorigin?has_content> crossorigin="${resource.crossorigin}"</#if><#if resource.hasDefer> defer</#if><#if resource.hasAsync> async</#if><#if resource.blocking?has_content> blocking="${resource.blocking}"</#if>></script> |
|
|
||
| <#macro renderScripts resources pathPrefix defaultScriptType=""> | ||
| <#list resources as resource> | ||
| <script src="${pathPrefix}/${resource.path}"<#if resource.type?has_content> type="${resource.type}"<#elseif defaultScriptType?has_content> type="${defaultScriptType}"</#if><#if resource.media?has_content> media="${resource.media}"</#if><#if resource.integrity?has_content> integrity="${resource.integrity}"</#if><#if resource.crossorigin?has_content> crossorigin="${resource.crossorigin}"</#if><#if resource.hasDefer> defer</#if><#if resource.hasAsync> async</#if><#if resource.blocking?has_content> blocking="${resource.blocking}"</#if>></script> |
|
|
||
| <#macro renderScripts resources pathPrefix defaultScriptType=""> | ||
| <#list resources as resource> | ||
| <script src="${pathPrefix}/${resource.path}"<#if resource.type?has_content> type="${resource.type}"<#elseif defaultScriptType?has_content> type="${defaultScriptType}"</#if><#if resource.media?has_content> media="${resource.media}"</#if><#if resource.integrity?has_content> integrity="${resource.integrity}"</#if><#if resource.crossorigin?has_content> crossorigin="${resource.crossorigin}"</#if><#if resource.hasDefer> defer</#if><#if resource.hasAsync> async</#if><#if resource.blocking?has_content> blocking="${resource.blocking}"</#if>></script> |
| * styles - Space-separated list of styles to include | ||
| * scripts - Space-separated list of scripts to include | ||
| * favicons - Space-separated list of favicons to include, or dot-notation entries (see below) | ||
| * locales - Comma-separated list of supported locales |
| Supported attributes: | ||
|
|
||
| * styles / stylesCommon: `media`, `integrity`, `crossorigin` | ||
| * scripts: `media`, `integrity`, `defer`, `async`, `type`, `crossorigin`, `blocking` |
|
Before I let Copilot do its review, I ran a Claude review with Opus. Both found different issues. I'm asking Claude to post inline comments under my user id. We will see how that goes. |
There was a problem hiding this comment.
Adding the findings inline (replaces my earlier hidden summary). The parse → model → render split is clean and the parser tests are thorough; main concern is the macro bug below.
|
|
||
| <#macro renderScripts resources pathPrefix defaultScriptType=""> | ||
| <#list resources as resource> | ||
| <script src="${pathPrefix}/${resource.path}"<#if resource.type?has_content> type="${resource.type}"<#elseif defaultScriptType?has_content> type="${defaultScriptType}"</#if><#if resource.media?has_content> media="${resource.media}"</#if><#if resource.integrity?has_content> integrity="${resource.integrity}"</#if><#if resource.crossorigin?has_content> crossorigin="${resource.crossorigin}"</#if><#if resource.hasDefer> defer</#if><#if resource.hasAsync> async</#if><#if resource.blocking?has_content> blocking="${resource.blocking}"</#if>></script> |
There was a problem hiding this comment.
Likely rendering bug. resource.hasDefer / resource.hasAsync are accessed without parentheses, but hasDefer()/hasAsync() are not JavaBean getters (getX/isX), so FreeMarker's bean wrapper resolves them to the method object, not a boolean — <#if methodModel> raises "Expected a boolean…". Existing templates call no-arg booleans with parens (e.g. auth.showUsername()). A theme that sets scripts.x.defer=true would 500. Use <#if resource.hasDefer()> / resource.hasAsync(), or rename to isDefer()/isAsync(). No test currently renders these macros, so please add one covering a defer/async script. (Same fix needed in all 5 copies of this file.)
| @@ -0,0 +1,17 @@ | |||
| <#macro renderStyles resources pathPrefix> | |||
| <#list resources as resource> | |||
| <link href="${pathPrefix}/${resource.path}" rel="stylesheet"<#if resource.media?has_content> media="${resource.media}"</#if><#if resource.integrity?has_content> integrity="${resource.integrity}"</#if><#if resource.crossorigin?has_content> crossorigin="${resource.crossorigin}"</#if> /> | |||
There was a problem hiding this comment.
Unescaped attribute values. Property values are interpolated raw into HTML attributes here (and in renderScripts/renderFavicons below) — e.g. media="${resource.media}". A value containing a double-quote breaks out of the attribute. These are theme-author controlled so severity is limited, but since themes can be uploaded/community-sourced, ${resource.media?html} (or an HTML output format on the macro file) would be good defense-in-depth.
| @@ -0,0 +1,17 @@ | |||
| <#macro renderStyles resources pathPrefix> | |||
There was a problem hiding this comment.
Duplication. This macro file is added byte-for-byte in 5 places (base/account, base/admin, base/login community, base/login resources, welcome). Any change — including the hasDefer() fix above — must be made in all five and they will drift. Consider a single shared location via theme inheritance, or at least a comment marking these as synchronized copies.
| <title>${title!}</title> | ||
| <link rel="icon" href="${url.resourcesPath}/img/favicon.ico" /> | ||
| <#if properties.stylesCommon?has_content> | ||
| <#if themeResources?? && themeResources.favicons?has_content> |
There was a problem hiding this comment.
Behavior change worth noting. Login previously always rendered a hardcoded img/favicon.ico. Now parseLegacyFavicon populates favicons from the favIcon property (which login historically ignored), and rel becomes icon. So a theme that set favIcon for account now changes login/welcome too. Probably harmless, but please call it out in the PR description.
| <#list properties.styles?split(' ') as style> | ||
| <link rel="stylesheet" href="${resourceUrl}/${style}"> | ||
| </#list> | ||
| <#if themeResources?? && themeResources.styles?has_content> |
There was a problem hiding this comment.
Inconsistent fallback. template.ftl guards styles with <#if themeResources??…><#elseif properties.styles?has_content>, but here the <#elseif properties.styles> arm is dropped. It works only because the parser folds legacy styles into themeResources; if themeResources is ever null on this path, styles silently vanish. Worth making the two paths consistent.
| continue; | ||
| } | ||
| String id = matcher.group(2); | ||
| if ("order".equals(id)) { |
There was a problem hiding this comment.
order is effectively a reserved resource id (skipped here), but that isn't documented alongside the "ids must not contain dots" note. A theme using a resource id of order would be silently dropped — worth a doc line.<
10BC8
/p>
| && realm.getAttribute("darkMode", true)); | ||
| } catch (IOException e) { | ||
| e.printStackTrace(); | ||
| logger.warn("Failed to load theme properties", e); |
There was a problem hiding this comment.
Nice cleanup — replacing e.printStackTrace() with logger.warn(...) here. 👍
|
@ssilvert addressed the review comments |
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
| String flat = properties.getProperty(type); | ||
| if (flat != null && !flat.isBlank()) { | ||
| for (String path : flat.trim().split("\\s+")) { | ||
| if (!path.isEmpty()) { | ||
| result.add(buildDescriptor(path, favicon)); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Good catch — this is a real inconsistency. The space-separated favicons= list goes through buildDescriptor(path, favicon) with no normalization, while both the dot-notation path and parseLegacyFavicon strip a leading /. With favicons=/favicon.svg, renderFavicons then emits href="${pathPrefix}//favicon.svg".
The suggested patch works. One refinement: all three favicon paths converge on Builder.buildFavicon(), so normalizing the leading slash once there (or via a small normalizeFaviconPath helper) would fix this and remove the two existing inline strips — one place to keep correct instead of three. Worth a quick parser test for the space-separated favicon case too, since none currently covers it.
|
@edewit Claude was happy with all your fixes. Copilot found one more issue, but Claude thinks Copilot's fix is sub-optimal. What fun! See inline comment with Claude's response to Copilot. |
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
|
done |
* made style sheet imports more flexible This extends the way stylesheets are rendered and is backwards compatible. But now attibutes can be added by using the dot notation. fixes: keycloak#22042 Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com> * PR review fixes Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com> * favIcon path normilize Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com> --------- Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>