diff options
| author | 2023-07-11 19:58:55 +0200 | |
|---|---|---|
| committer | 2023-07-11 19:58:55 +0200 | |
| commit | a18c71929868403af33fdaff2265a74e4c552c13 (patch) | |
| tree | 95d17e8be47d025c5e294554bed2c3bf5ad7b7d6 | |
| parent | Updated RELEASE_NOTES. (diff) | |
| download | snac2-a18c71929868403af33fdaff2265a74e4c552c13.tar.gz snac2-a18c71929868403af33fdaff2265a74e4c552c13.tar.xz snac2-a18c71929868403af33fdaff2265a74e4c552c13.zip | |
Fixed crash.
| -rw-r--r-- | html.c | 38 |
1 files changed, 26 insertions, 12 deletions
| @@ -1147,47 +1147,61 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local, | |||
| 1147 | continue; | 1147 | continue; |
| 1148 | 1148 | ||
| 1149 | if (xs_startswith(t, "image/")) { | 1149 | if (xs_startswith(t, "image/")) { |
| 1150 | char *url = xs_dict_get(v, "url"); | 1150 | char *url = xs_dict_get(v, "url"); |
| 1151 | xs *name = encode_html(xs_dict_get(v, "name")); | 1151 | char *name = xs_dict_get(v, "name"); |
| 1152 | 1152 | ||
| 1153 | if (url != NULL) { | 1153 | if (url != NULL) { |
| 1154 | if (xs_is_null(name)) | 1154 | if (xs_is_null(name)) |
| 1155 | name = ""; | 1155 | name = ""; |
| 1156 | |||
| 1157 | xs *es1 = encode_html(name); | ||
| 1156 | xs *s1 = xs_fmt( | 1158 | xs *s1 = xs_fmt( |
| 1157 | "<a href=\"%s\" target=\"_blank\"><img src=\"%s\" alt=\"%s\" title=\"%s\" loading=\"lazy\"/></a>\n", | 1159 | "<a href=\"%s\" target=\"_blank\"><img src=\"%s\" alt=\"%s\" title=\"%s\" loading=\"lazy\"/></a>\n", |
| 1158 | url, url, name, name); | 1160 | url, url, es1, es1); |
| 1159 | 1161 | ||
| 1160 | s = xs_str_cat(s, s1); | 1162 | s = xs_str_cat(s, s1); |
| 1161 | } | 1163 | } |
| 1162 | } | 1164 | } |
| 1163 | else | 1165 | else |
| 1164 | if (xs_startswith(t, "video/")) { | 1166 | if (xs_startswith(t, "video/")) { |
| 1165 | char *url = xs_dict_get(v, "url"); | 1167 | char *url = xs_dict_get(v, "url"); |
| 1166 | xs *name = encode_html(xs_dict_get(v, "name")); | 1168 | char *name = xs_dict_get(v, "name"); |
| 1167 | 1169 | ||
| 1168 | if (url != NULL) { | 1170 | if (url != NULL) { |
| 1169 | xs *s1 = xs_fmt("<video style=\"max-width: 90vw; max-height: 70vh;\" controls src=\"%s\">Video: <a href=\"%s\">%s</a></video>\n", url, url, name ? name : "No description."); | 1171 | if (xs_is_null(name)) |
| 1172 | name = "No description"; | ||
| 1173 | |||
| 1174 | xs *es1 = encode_html(name); | ||
| 1175 | xs *s1 = xs_fmt("<video style=\"max-width: 90vw; max-height: 70vh;\" controls src=\"%s\">Video: <a href=\"%s\">%s</a></video>\n", url, url, es1); | ||
| 1170 | 1176 | ||
| 1171 | s = xs_str_cat(s, s1); | 1177 | s = xs_str_cat(s, s1); |
| 1172 | } | 1178 | } |
| 1173 | } | 1179 | } |
| 1174 | else | 1180 | else |
| 1175 | if (xs_startswith(t, "audio/")) { | 1181 | if (xs_startswith(t, "audio/")) { |
| 1176 | char *url = xs_dict_get(v, "url"); | 1182 | char *url = xs_dict_get(v, "url"); |
| 1177 | xs *name = encode_html(xs_dict_get(v, "name")); | 1183 | char *name = xs_dict_get(v, "name"); |
| 1178 | 1184 | ||
| 1179 | if (url != NULL) { | 1185 | if (url != NULL) { |
| 1180 | xs *s1 = xs_fmt("<audio style=\"max-width: 90vw\" controls src=\"%s\">Audio: <a href=\"%s\">%s</a></audio>\n", url, url, name ? name : "No description."); | 1186 | if (xs_is_null(name)) |
| 1187 | name = "No description"; | ||
| 1188 | |||
| 1189 | xs *es1 = encode_html(name); | ||
| 1190 | xs *s1 = xs_fmt("<audio style=\"max-width: 90vw\" controls src=\"%s\">Audio: <a href=\"%s\">%s</a></audio>\n", url, url, es1); | ||
| 1181 | 1191 | ||
| 1182 | s = xs_str_cat(s, s1); | 1192 | s = xs_str_cat(s, s1); |
| 1183 | } | 1193 | } |
| 1184 | } | 1194 | } |
| 1185 | else { | 1195 | else { |
| 1186 | char *url = xs_dict_get(v, "url"); | 1196 | char *url = xs_dict_get(v, "url"); |
| 1187 | xs *name = encode_html(xs_dict_get(v, "name")); | 1197 | char *name = xs_dict_get(v, "name"); |
| 1188 | 1198 | ||
| 1189 | if (url != NULL) { | 1199 | if (url != NULL) { |
| 1190 | xs *s1 = xs_fmt("<a href=\"%s\">Attachment: %s</a>", url, name ? name : "No description"); | 1200 | if (xs_is_null(name)) |
| 1201 | name = "No description"; | ||
| 1202 | |||
| 1203 | xs *es1 = encode_html(name); | ||
| 1204 | xs *s1 = xs_fmt("<a href=\"%s\">Attachment: %s</a>", url, es1); | ||
| 1191 | 1205 | ||
| 1192 | s = xs_str_cat(s, s1); | 1206 | s = xs_str_cat(s, s1); |
| 1193 | } | 1207 | } |