openhab / openhab-addons

Add-ons for openHAB
https://www.openhab.org/
Eclipse Public License 2.0
1.86k stars 3.57k forks source link

[iCalendar] Strip HTML from Command Tags #12486

Open BigGeorgeTx opened 2 years ago

BigGeorgeTx commented 2 years ago

I have recently begun using the iCalendar binding to supply the color themes for my exterior lights. I am using Google Calendar, and it works except when the text of the note field is formatted, which results in HTML code in the command. Here is what I saw getting ready for St. Patrick's Day tomorrow: 2022-03-16 17:45:01.372 [TRACE] [.icalendar.internal.logic.CommandTag] - Command Tag Trace: "<html-blob><pre><code>BEGIN:ExteriorLightsColorScheme:"green"</code></pre></html-blob>" => NOT a (valid) Command Tag!

I found in the community a thread indicating that is necessary to make sure it is plain text: https://community.openhab.org/t/icalendar-command-tags-not-working/116680/4, which helped. But I find that Google frequently, without asking, reenables formatting. It would be great if the binding would strip out the HTML code and use the text.

Your Environment

I don't think this matters much, but I'm running openHAB 3.3M2 on a Pi 4B using openhabian.

BigGeorgeTx commented 1 year ago

For me, this has gone from difficult to impossible. Google Calendar adds html to the description no matter what I do. I click on the remove formatting button, which used to work, but now the html is added when I save it. So the Command Tags won't work.

daMihe commented 1 year ago

Could you please provide an example ical file (will be included in tests here, so without personal details please).

BigGeorgeTx commented 1 year ago

Here is one event from my Google calendar exported as an iCal zip file. It appears to have the troubling HTML in the body. Please let me know if I can be of further assistance.

OpenHAB test.ical.zip

BigGeorgeTx commented 1 year ago

I'm not a java programmer, but I looked through the code. I can generally follow it even if I can't write it.

I think was is needed is to add to the existing code that tries to clean up the lineInput an HTML parser that will remove the offending HTM.

In CommandTag.java: public CommandTag(String inputLine) throws IllegalArgumentException { this.inputLine = inputLine.trim();

    if (!CommandTagType.prefixValid(inputLine)) {
        throw new IllegalArgumentException(
                String.format("Command Tag Exception \"%s\" => Bad tag prefix!", inputLine));
    }

    if (!inputLine.contains(":")) {
        throw new IllegalArgumentException(
                String.format("Command Tag Exception \"%s\" => Missing \":\" delimiters!", inputLine));
    }

    String[] fields = inputLine.split(":");
    if (fields.length < 3) {
        throw new IllegalArgumentException(
                String.format("Command Tag Exception \"%s\" => Not enough fields!", inputLine));
    }

Add one of the parsers (Jsoup, HTMLCleaner or Jerico referenced here: https://www.baeldung.com/java-remove-html-tags

daMihe commented 1 year ago

Technically, this is simple solvable, as html tags look always the same and only the text without formatting is required in the tag executor. But i'm currently waiting on a review of MR 14766 which i'd like to base on as it has been refactored a bit.

BigGeorgeTx commented 1 year ago

Thanks. I’ll watch for the update.

On Sun, Sep 3, 2023 at 5:41 AM Michael Wodniok @.***> wrote:

Technically, this is simple solvable, as html tags look always the same and only the text without formatting is required in the tag executor. But i'm currently waiting on a review of MR 14766 https://github.com/openhab/openhab-addons/pull/14766 which i'd like to base on as it has been refactored a bit.

— Reply to this email directly, view it on GitHub https://github.com/openhab/openhab-addons/issues/12486#issuecomment-1704252417, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADEQZLZ2SV2SXTCUZEZ3MY3XYRUH7ANCNFSM5Q5IM6SA . You are receiving this because you authored the thread.Message ID: @.***>