Fossil SCM
Simplified some JSON quoting in chat.c. Bypass the paste-from-clipboard handling if the paste target is the input text field, to avoid a console-level error when the text cannot be parsed as an image. TODO: figure out how to handle the paste-image case properly when the event target is the text input field.
Commit
2fe8d7c4b1d271c58c756aa9a801c979f8f4f7c3ae3d7bb22ca52614570a7ce1
Parent
b604154c3822b45…
2 files changed
+6
-6
+2
+6
-6
| --- src/chat.c | ||
| +++ src/chat.c | ||
| @@ -106,11 +106,11 @@ | ||
| 106 | 106 | @ </div> |
| 107 | 107 | @ <div id='chat-input-file'> |
| 108 | 108 | @ <span>File:</span> |
| 109 | 109 | @ <input type="file" name="file"> |
| 110 | 110 | @ <div id='chat-pasted-image'> |
| 111 | - @ Or paste an image from clipboard, if supported by your | |
| 111 | + @ Or paste an image from the clipboard, if supported by your | |
| 112 | 112 | @ environment.<br><img> |
| 113 | 113 | @ </div> |
| 114 | 114 | @ </div> |
| 115 | 115 | @ </div> |
| 116 | 116 | @ </form> |
| @@ -262,25 +262,25 @@ | ||
| 262 | 262 | const char *zFMime = db_column_text(&q1, 6); |
| 263 | 263 | char *zMsg; |
| 264 | 264 | cnt++; |
| 265 | 265 | blob_append(&json, zSep, -1); |
| 266 | 266 | zSep = ",\n"; |
| 267 | - blob_appendf(&json, "{\"msgid\":%d,\"mtime\":\"%j\",", id, zDate); | |
| 268 | - blob_appendf(&json, "\"xfrom\":\"%j\",", zFrom); | |
| 269 | - blob_appendf(&json, "\"uclr\":\"%j\",", hash_color(zFrom)); | |
| 267 | + blob_appendf(&json, "{\"msgid\":%d,\"mtime\":%!j,", id, zDate); | |
| 268 | + blob_appendf(&json, "\"xfrom\":%!j,", zFrom); | |
| 269 | + blob_appendf(&json, "\"uclr\":%!j,", hash_color(zFrom)); | |
| 270 | 270 | |
| 271 | 271 | /* TBD: Convert the raw message into HTML, perhaps by running it |
| 272 | 272 | ** through a text formatter, or putting markup on @name phrases, |
| 273 | 273 | ** etc. */ |
| 274 | 274 | zMsg = mprintf("%h", zRawMsg); |
| 275 | - blob_appendf(&json, "\"xmsg\":\"%j\",", zMsg); | |
| 275 | + blob_appendf(&json, "\"xmsg\":%!j,", zMsg); | |
| 276 | 276 | fossil_free(zMsg); |
| 277 | 277 | |
| 278 | 278 | if( nByte==0 ){ |
| 279 | 279 | blob_appendf(&json, "\"fsize\":0}"); |
| 280 | 280 | }else{ |
| 281 | - blob_appendf(&json, "\"fsize\":%d,\"fname\":\"%j\",\"fmime\":\"%j\"}", | |
| 281 | + blob_appendf(&json, "\"fsize\":%d,\"fname\":%!j,\"fmime\":%!j}", | |
| 282 | 282 | nByte, zFName, zFMime); |
| 283 | 283 | } |
| 284 | 284 | } |
| 285 | 285 | if( cnt ){ |
| 286 | 286 | blob_append(&json, "\n]}", 3); |
| 287 | 287 |
| --- src/chat.c | |
| +++ src/chat.c | |
| @@ -106,11 +106,11 @@ | |
| 106 | @ </div> |
| 107 | @ <div id='chat-input-file'> |
| 108 | @ <span>File:</span> |
| 109 | @ <input type="file" name="file"> |
| 110 | @ <div id='chat-pasted-image'> |
| 111 | @ Or paste an image from clipboard, if supported by your |
| 112 | @ environment.<br><img> |
| 113 | @ </div> |
| 114 | @ </div> |
| 115 | @ </div> |
| 116 | @ </form> |
| @@ -262,25 +262,25 @@ | |
| 262 | const char *zFMime = db_column_text(&q1, 6); |
| 263 | char *zMsg; |
| 264 | cnt++; |
| 265 | blob_append(&json, zSep, -1); |
| 266 | zSep = ",\n"; |
| 267 | blob_appendf(&json, "{\"msgid\":%d,\"mtime\":\"%j\",", id, zDate); |
| 268 | blob_appendf(&json, "\"xfrom\":\"%j\",", zFrom); |
| 269 | blob_appendf(&json, "\"uclr\":\"%j\",", hash_color(zFrom)); |
| 270 | |
| 271 | /* TBD: Convert the raw message into HTML, perhaps by running it |
| 272 | ** through a text formatter, or putting markup on @name phrases, |
| 273 | ** etc. */ |
| 274 | zMsg = mprintf("%h", zRawMsg); |
| 275 | blob_appendf(&json, "\"xmsg\":\"%j\",", zMsg); |
| 276 | fossil_free(zMsg); |
| 277 | |
| 278 | if( nByte==0 ){ |
| 279 | blob_appendf(&json, "\"fsize\":0}"); |
| 280 | }else{ |
| 281 | blob_appendf(&json, "\"fsize\":%d,\"fname\":\"%j\",\"fmime\":\"%j\"}", |
| 282 | nByte, zFName, zFMime); |
| 283 | } |
| 284 | } |
| 285 | if( cnt ){ |
| 286 | blob_append(&json, "\n]}", 3); |
| 287 |
| --- src/chat.c | |
| +++ src/chat.c | |
| @@ -106,11 +106,11 @@ | |
| 106 | @ </div> |
| 107 | @ <div id='chat-input-file'> |
| 108 | @ <span>File:</span> |
| 109 | @ <input type="file" name="file"> |
| 110 | @ <div id='chat-pasted-image'> |
| 111 | @ Or paste an image from the clipboard, if supported by your |
| 112 | @ environment.<br><img> |
| 113 | @ </div> |
| 114 | @ </div> |
| 115 | @ </div> |
| 116 | @ </form> |
| @@ -262,25 +262,25 @@ | |
| 262 | const char *zFMime = db_column_text(&q1, 6); |
| 263 | char *zMsg; |
| 264 | cnt++; |
| 265 | blob_append(&json, zSep, -1); |
| 266 | zSep = ",\n"; |
| 267 | blob_appendf(&json, "{\"msgid\":%d,\"mtime\":%!j,", id, zDate); |
| 268 | blob_appendf(&json, "\"xfrom\":%!j,", zFrom); |
| 269 | blob_appendf(&json, "\"uclr\":%!j,", hash_color(zFrom)); |
| 270 | |
| 271 | /* TBD: Convert the raw message into HTML, perhaps by running it |
| 272 | ** through a text formatter, or putting markup on @name phrases, |
| 273 | ** etc. */ |
| 274 | zMsg = mprintf("%h", zRawMsg); |
| 275 | blob_appendf(&json, "\"xmsg\":%!j,", zMsg); |
| 276 | fossil_free(zMsg); |
| 277 | |
| 278 | if( nByte==0 ){ |
| 279 | blob_appendf(&json, "\"fsize\":0}"); |
| 280 | }else{ |
| 281 | blob_appendf(&json, "\"fsize\":%d,\"fname\":%!j,\"fmime\":%!j}", |
| 282 | nByte, zFName, zFMime); |
| 283 | } |
| 284 | } |
| 285 | if( cnt ){ |
| 286 | blob_append(&json, "\n]}", 3); |
| 287 |
+2
| --- src/chat.js | ||
| +++ src/chat.js | ||
| @@ -28,10 +28,11 @@ | ||
| 28 | 28 | }); |
| 29 | 29 | /* Handle image paste from clipboard. TODO: confirm that we only |
| 30 | 30 | paste images here (silently ignore non-image data), or change the |
| 31 | 31 | related code to support non-image pasting/posting. */ |
| 32 | 32 | document.onpaste = function(event){ |
| 33 | + if(form.msg === event.target) return; | |
| 33 | 34 | const items = event.clipboardData.items; |
| 34 | 35 | ImagePasteState.blob = items[0].getAsFile(); |
| 35 | 36 | const reader = new FileReader(); |
| 36 | 37 | reader.onload = function(event){ |
| 37 | 38 | ImagePasteState.imgTag.setAttribute('src', event.target.result); |
| @@ -177,10 +178,11 @@ | ||
| 177 | 178 | if(poll.running) return; |
| 178 | 179 | poll.running = true; |
| 179 | 180 | fetch("chat-poll/" + mxMsg) |
| 180 | 181 | .then(x=>x.json()) |
| 181 | 182 | .then(y=>newcontent(y)) |
| 183 | + .catch(e=>console.error(e)) | |
| 182 | 184 | .finally(()=>poll.running=false) |
| 183 | 185 | } |
| 184 | 186 | poll(); |
| 185 | 187 | setInterval(poll, 1000); |
| 186 | 188 | })(); |
| 187 | 189 |
| --- src/chat.js | |
| +++ src/chat.js | |
| @@ -28,10 +28,11 @@ | |
| 28 | }); |
| 29 | /* Handle image paste from clipboard. TODO: confirm that we only |
| 30 | paste images here (silently ignore non-image data), or change the |
| 31 | related code to support non-image pasting/posting. */ |
| 32 | document.onpaste = function(event){ |
| 33 | const items = event.clipboardData.items; |
| 34 | ImagePasteState.blob = items[0].getAsFile(); |
| 35 | const reader = new FileReader(); |
| 36 | reader.onload = function(event){ |
| 37 | ImagePasteState.imgTag.setAttribute('src', event.target.result); |
| @@ -177,10 +178,11 @@ | |
| 177 | if(poll.running) return; |
| 178 | poll.running = true; |
| 179 | fetch("chat-poll/" + mxMsg) |
| 180 | .then(x=>x.json()) |
| 181 | .then(y=>newcontent(y)) |
| 182 | .finally(()=>poll.running=false) |
| 183 | } |
| 184 | poll(); |
| 185 | setInterval(poll, 1000); |
| 186 | })(); |
| 187 |
| --- src/chat.js | |
| +++ src/chat.js | |
| @@ -28,10 +28,11 @@ | |
| 28 | }); |
| 29 | /* Handle image paste from clipboard. TODO: confirm that we only |
| 30 | paste images here (silently ignore non-image data), or change the |
| 31 | related code to support non-image pasting/posting. */ |
| 32 | document.onpaste = function(event){ |
| 33 | if(form.msg === event.target) return; |
| 34 | const items = event.clipboardData.items; |
| 35 | ImagePasteState.blob = items[0].getAsFile(); |
| 36 | const reader = new FileReader(); |
| 37 | reader.onload = function(event){ |
| 38 | ImagePasteState.imgTag.setAttribute('src', event.target.result); |
| @@ -177,10 +178,11 @@ | |
| 178 | if(poll.running) return; |
| 179 | poll.running = true; |
| 180 | fetch("chat-poll/" + mxMsg) |
| 181 | .then(x=>x.json()) |
| 182 | .then(y=>newcontent(y)) |
| 183 | .catch(e=>console.error(e)) |
| 184 | .finally(()=>poll.running=false) |
| 185 | } |
| 186 | poll(); |
| 187 | setInterval(poll, 1000); |
| 188 | })(); |
| 189 |