Skip to content

getSelector() generating invalid selector when there are leading or trailing spaces in the class. #312

Closed
@Tiggerito

Description

@Tiggerito

? '.' + el.className.replace(/\s+/g, '.')

We picked up a scenario where getSelector() created an invalid selector:

class="layout-block product-layout-block "

The key thing is the space after the class names. This results in an extra dot being added to the selector:

'layout-block.product-layout-block.'

A simple fix would be to trim the class first:

? '.' + el.className.trim().replace(/\s+/g, '.')

It's probably also with checking for class names with just a space and IDs with leading or trailing spaces.

Is there any reason to limit the selector to 99 characters at this point? I know GA4 has a limit, but I split the selector in two to get around it, and now that will not work because of this limit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions