Skip to content

Commit 8e702ff

Browse files
committed
Show a posted news item as text in the other sessions of the AMC sample
Z2UI5_CL_SMPS_APP_489 put the text that arrives over the channel straight into a FeedListItem, which renders its text as FormattedText - so markup one user typed (a link, bold, a list) reached every other open session as markup. The text is now HTML-escaped on the way into the feed, the way Z2UI5_CL_SMPS_APP_014 already does it for its chat. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Te3BRpRpxNhZAYnrQL6Gdt
1 parent f3ca988 commit 8e702ff

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

‎src/07/z2ui5_cl_smps_app_489.clas.abap‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ CLASS z2ui5_cl_smps_app_489 DEFINITION PUBLIC.
5252
RETURNING
5353
VALUE(result) TYPE string.
5454

55+
"! the three characters FormattedText reads as markup - escaped, so a
56+
"! news item somebody else posted shows the text they typed
57+
METHODS html_escape
58+
IMPORTING
59+
val TYPE string
60+
RETURNING
61+
VALUE(result) TYPE string.
62+
5563
ENDCLASS.
5664

5765

@@ -148,9 +156,12 @@ CLASS z2ui5_cl_smps_app_489 IMPLEMENTATION.
148156
RETURN.
149157
ENDIF.
150158

159+
" a FeedListItem renders its text as FormattedText, and this text
160+
" was typed by whoever is on the channel - escaped, so a posted <a>
161+
" or <strong> reaches the other sessions as the text it is
151162
INSERT VALUE ty_s_news(
152-
text = json_get_string( json = ws_message
153-
name = `text` )
163+
text = html_escape( json_get_string( json = ws_message
164+
name = `text` ) )
154165
author = json_get_string( json = ws_message
155166
name = `author` ) ) INTO TABLE t_news.
156167

@@ -194,6 +205,16 @@ CLASS z2ui5_cl_smps_app_489 IMPLEMENTATION.
194205
ENDMETHOD.
195206

196207

208+
METHOD html_escape.
209+
210+
" the ampersand FIRST, or the other two would be escaped twice
211+
result = replace( val = val sub = `&` with = `&amp;` occ = 0 ).
212+
result = replace( val = result sub = `<` with = `&lt;` occ = 0 ).
213+
result = replace( val = result sub = `>` with = `&gt;` occ = 0 ).
214+
215+
ENDMETHOD.
216+
217+
197218
METHOD json_get_string.
198219

199220
" Reads one string field of the flat object json_build( ) writes. Finding

0 commit comments

Comments
 (0)