Skip to content
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

useStyle: matching document.getElementById(id) when id is undefined could break css injection #17091

Closed
luca-peruzzo opened this issue Dec 17, 2024 · 1 comment · Fixed by #17092
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@luca-peruzzo
Copy link
Contributor

Describe the bug

In useStyle.ts there is this code:

styleRef = this.document.querySelector(`style[data-primeng-style-id="${name}"]`) || this.document.getElementById(id) || this.document.createElement('style');

when we have not already injected a specific css (for example inputotp-variables) id is undefined and this.document.getElementById(id) could match an element that has id="undefined" for example <span id="undefined">content</span> causing a style issue for missing css.
It is very uncommon (and ugly) to create an id with value "undefined" but this isn't forbidden by html rules.

Environment

Angular v18 webapp

Reproducer

https://stackblitz.com/edit/github-xypllzpu

Angular version

18.2.2

PrimeNG version

18.0.0

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

22.11.0

Browser(s)

No response

Steps to reproduce the behavior

  1. Just run the stackblitz repo

Expected behavior

id="undefined" must not break style injection

@luca-peruzzo luca-peruzzo added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Dec 17, 2024
luca-peruzzo added a commit to luca-peruzzo/primeng that referenced this issue Dec 17, 2024
@mertsincan mertsincan added Resolution: Needs More Information More information about the issue is needed to find a correct solution and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Dec 17, 2024
Copy link

More information is needed to find a solution. A runnable StackBlitz example and additional details would be helpful.

@mertsincan mertsincan added Type: Bug Issue contains a bug related to a specific component. Something about the component is not working and removed Resolution: Needs More Information More information about the issue is needed to find a correct solution labels Dec 17, 2024
@mertsincan mertsincan added this to the 18.0.1 milestone Dec 17, 2024
@github-project-automation github-project-automation bot moved this to Review in PrimeNG Dec 17, 2024
@mertsincan mertsincan moved this from Review to Done in PrimeNG Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants