DataPower

DataPower

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
  • 1.  Remove emoji from input request

    Posted Thu April 10, 2025 12:57 PM

    Hello all

    IS there a way to remove all emoji contains into input request

    Example of request

    <xml>
        <mail_body>
            <CorpsMail>Le jeu. 10 avr. 2025 à 17:39,  a écrit : > > > Le jeu. 10 avr. 2025 à 17:37,  a > écrit : > >> >> >> Le jeu. 10 avr. 2025 à 17:29,  a >> écrit : >> >>> >>> >>> Le jeu. 10 avr. 2025 à 15:11,  a >>> écrit : >>> >>>> 😁☺️🥰😘😚😃😀😁 >>>> >>>> Le jeu. 10 avr. 2025 à 12:03,  a >>>> écrit : >>>> >>>>> >>>>> >>>>> Le mer. 9 avr. 2025 à 16:50,  a >>>>> écrit : >>>>> >>>>>> dz >>>>>> >>>>></CorpsMail>
        </mail_body>
    </xml>



    ------------------------------
    D@viiid
    ------------------------------


  • 2.  RE: Remove emoji from input request

    Posted Thu April 10, 2025 12:58 PM

    I mean into datapower MPG :)



    ------------------------------
    D@viiid
    ------------------------------



  • 3.  RE: Remove emoji from input request

    Posted Fri April 11, 2025 02:46 AM

    Hi,
    here is the easy part.
    First have a xform action with a stylesheet or a GatewayScript action with input contect INPUT and output context _INPUT_
    The change all actions with INPUT as input context to use _INPUT_ instead.

    In a XSLT you can use XPath 1.0 function "translate()" to delete characters:
    https://www.w3.org/TR/1999/REC-xpath-19991116/#function-translate

    (eg. "translate(., '👍', '')" with empry replacement string)

    The problem is that you need to define what you consider an emoji.
    You can easily exclude all unicode characters above BMP (Basic Multilingual Plane).

    So with unicode > Ux0FFFF.

    But do you consider clock symbols as unicode as well
    https://commons.wikimedia.org/wiki/Category:U%2B23F0

    or chess pieces?
    https://en.wikipedia.org/wiki/Chess_symbols_in_Unicode

    The problem you have is to exactly define "what" you want to remove.
    If you know that, doing the removal with XSLT/GatewayScript is not difficult.



    ------------------------------
    Hermann Stamm-Wilbrandt
    Compiler Level 3 support, IBM DataPower Gateways
    IBM
    Boeblingen
    ------------------------------



  • 4.  RE: Remove emoji from input request

    Posted Fri April 11, 2025 04:12 AM

    Hi Hermann

    It's been a long time since you solved one of my problems :)

    You're absolutely right: I need to define what an emofi is and I don't want to have an endless list of emoji to replace. And I don't want to update that list with new emoji.

    So I'm interested in replacing all the characters above BMP 

    Could you explain how to implement this solution?



    ------------------------------
    D@viiid
    ------------------------------



  • 5.  RE: Remove emoji from input request

    Posted Fri April 11, 2025 05:45 AM

    Hermann,

    I used this gatewayscript below

    session.input.readAsBuffer(function (readAsBufferError, data) {
       if (readAsBufferError) {
          console.error('Error on readAsBuffer: ' + readAsBufferError);
       } else {
          var content = data.toString();
          var cleaned = content.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g, '');
          session.output.write(cleaned);
       } 
     }); 

    I don't understand why it works in a MPG with 'soap' as request type, but it doesn't work in a WSP..

    Do you have an idea ?



    ------------------------------
    D@viiid
    ------------------------------



  • 6.  RE: Remove emoji from input request

    Posted Fri April 11, 2025 06:41 AM
    Edited by Hermann Stamm-Wilbrandt Fri April 11, 2025 06:41 AM

    Hi Daviid,

    your script works indeed:

    $ echo -e "foo\xF0\x9F\x91\x8Dbar"
    foo👍bar
    $ coproc2 onlyBmp.js <(echo -e "foo\xF0\x9F\x91\x8Dbar") http://127.0.0.1:2227 
    foobar
    $

    The problem is that your script is a Non-XML script, and INPUT seems to be available as is in MPGW, but not in WSP. You should use a GatewayScript with readAsXML() and only replace emojis for CorpsMail element.



    ------------------------------
    Hermann Stamm-Wilbrandt
    Compiler Level 3 support, IBM DataPower Gateways
    IBM
    Boeblingen
    ------------------------------



  • 7.  RE: Remove emoji from input request

    Posted Mon April 14, 2025 12:30 PM

    Hello Hermann

    Just a precision about the script you helped me to develop

    Why some smileys are not replace

    Example : 

    <ObjetMail>Re: Fwd: SG17-DSIN-2010-00230 test emoji dans l'objet🤨 🧠💑🐄🍀🐊🐝🐴🚨⛵🍜㊙️🅰️🈳❇️♻️💭🕕🕛🕜</ObjetMail>

    has been replace by

    <ObjetMail>Re: Fwd: SG17-DSIN-2010-00230 test emoji dans l'objet ⛵㊙️️❇️♻️</ObjetMail>

    It seems that some emojis are included in BMP.


    ❇️ --> U+2747 (sparkle) + U+FE0F (variation selector) :both are included in BMP

    Could you help me ? :)



    ------------------------------
    D@viiid
    ------------------------------



  • 8.  RE: Remove emoji from input request

    Posted Tue April 15, 2025 05:42 AM
    Edited by Hermann Stamm-Wilbrandt Tue April 15, 2025 05:49 AM

    Your code only removes Unicode characters not on BMP (Basic Multilingual Plane, the first 65536 characters).

    U+2747 (❇) is in BMP and therefore not removed by your code.
    You need to walk through all BMP characters and identify those that you want to exclude.
    That is needed because there is no function "isEmoji()".
    After you have identified the characters to remove, you need to enhance your code to remove them as well.

    Here you can quickly access the complete BMP in your browser in 8 parts:

    https://stamm-wilbrandt.de/xqib/A3/BMP_0_xq_html.pdf
    https://stamm-wilbrandt.de/xqib/A3/BMP_1_xq_html.pdf
    https://stamm-wilbrandt.de/xqib/A3/BMP_2_xq_html.pdf
    https://stamm-wilbrandt.de/xqib/A3/BMP_3_xq_html.pdf
    https://stamm-wilbrandt.de/xqib/A3/BMP_4_xq_html.pdf
    https://stamm-wilbrandt.de/xqib/A3/BMP_5_xq_html.pdf
    https://stamm-wilbrandt.de/xqib/A3/BMP_6_xq_html.pdf
    https://stamm-wilbrandt.de/xqib/A3/BMP_7_xq_html.pdf



    ------------------------------
    Hermann Stamm-Wilbrandt
    Compiler Level 3 support, IBM DataPower Gateways
    IBM
    Boeblingen
    ------------------------------