Skip to content

Importing AssetsPublicPathDirective breaks absolute URLs #37

@glewisorg

Description

@glewisorg

Following the README instructions, we imported directive AssetsPublicPathDirective into a component to rewrite src/href links that begin with assets/. We found that this directive breaks any href that uses interpolation to set its value to an absolute URL, with the result being that the href attribute is now missing.

For example, if myAbsoluteUrl="https://www.example.com/", the following displays the "My Link" text as not clickable. The href attribute is missing.
<a href="{{ myAbsoluteUrl }}">My Link</a>

The directive only sets the href attribute if the URL was changed by the rewrite. This assumes that otherwise the attribute has already been set for absolute URLs, but that is not the case. If you set a break point on line 23, you can verify that at that point, there is no href attribute listed under this.el.nativeElement. It must be set by the directive regardless of whether the rewritten value has changed or not.

https://github.com/ExLibrisGroup/customModule/blob/main/src/app/services/assets-public-path.directive.ts#L23-L26

While we were only testing with a[href], this bug may affect all attributes listed in the selector when using interpolation and absolute URLs:
img[src], source[src], link[href], script[src], a[href]

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