jumpinjackie / vscode-map-preview

VSCode map preview extension
MIT License
87 stars 14 forks source link

Add ellipsis to long properties in popup #56

Closed pilattebe closed 2 years ago

pilattebe commented 2 years ago

When you click on an item, long property values can make the popup extend past the size of the screen.

A simple CSS change can make the line clip at 30 char which would be the easiest solution.

// Line 25 in preview.js
        for (let key in props) {
            //Skip geometry
            if (key == feat.getGeometryName()) {
                continue;
            }
            html += "<tr>";
            html += "<td class='popup-attribute-key'>" + key + "</td>";
// BEFORE
            // html += "<td class='popup-attribute-value'>" + props[key] + "</td>";
// AFTER
            html += "<td class='popup-attribute-value' style='max-width: 30ch;text-overflow: ellipsis;overflow: hidden;white-space: nowrap;'>" + props[key] + "</td>";

            html += "</tr>";
        }

I hacked this together inline style but I'm sure someone more familiar with the extension will find the correct place to put CSS.


⚠️ Note: I think this piece of code contains a code injection vulnerability. So definitely don't open untrustworthy files with this extension as someone can put code in any of the properties and it will be run.

pilattebe commented 2 years ago

To be clear, I didn't add the vulnerability, I simply saw it and didn't fix it.

jumpinjackie commented 2 years ago

The feature property names and values are now cleaned with DOMPurify before they are concatted to the feature popup HTML