Skip to content

Leading and trailing space being added if PHP code is inside a form attribute #502

@wonderboyjon

Description

@wonderboyjon

Context:
I'm minify-ing a file that contains both HTML and PHP content. For the most part this works completely fine. However, in the case where I am using PHP to set/echo an HTML attribute value (when I need a variable calculated from code), the minification process adds a leading and trailing whitespace around the PHP tags. This especially causes problems if the attribute is an element ID, as the extra space ruins any JS selectors that are expecting an ID without white space.

Example:
<table id="<?php echo $this->escapeHtmlAttr($this->table_id); ?>" >

becomes

<table id=" <?php echo $this->escapeHtmlAttr($this->table_id); ?> " >

The only options I have set are
removeComments: true,
collapseWhitespace: true

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions