Feature #44642 ยป 0001-Include-seconds-in-pasted-image-filenames.patch
| app/assets/javascripts/attachments.js | ||
|---|---|---|
| 277 | 277 |
const inlineFilename = encodeURIComponent(sanitizedFilename) |
| 278 | 278 |
.replace(/[!()]/g, function(match) { return "%" + match.charCodeAt(0).toString(16) });
|
| 279 | 279 | |
| 280 |
const isFromClipboard = /^clipboard-\d{12}-[a-z0-9]{5}\.\w+$/.test(file.name);
|
|
| 280 |
const isFromClipboard = /^clipboard-\d{14}-[a-z0-9]{5}\.\w+$/.test(file.name);
|
|
| 281 | 281 |
let imageDisplayWidth; |
| 282 | 282 |
if (isFromClipboard) {
|
| 283 | 283 |
const imageWidth = await getImageWidth(file).catch(() => 0); |
| ... | ... | |
| 353 | 353 |
+ ('0'+date.getDate()).slice(-2)
|
| 354 | 354 |
+ ('0'+date.getHours()).slice(-2)
|
| 355 | 355 |
+ ('0'+date.getMinutes()).slice(-2)
|
| 356 |
+ ('0'+date.getSeconds()).slice(-2)
|
|
| 356 | 357 |
+ '-' + randomKey(5).toLocaleLowerCase() |
| 357 | 358 |
+ '.' + file.name.split('.').pop();
|
| 358 | 359 | |
| test/system/issues_test.rb | ||
|---|---|---|
| 217 | 217 |
assert_selector '.attachments_fields > span', :count => 2 |
| 218 | 218 |
end |
| 219 | 219 | |
| 220 |
def test_pasted_image_filename_should_include_seconds |
|
| 221 |
set_tmp_attachments_directory |
|
| 222 |
log_user('jsmith', 'jsmith')
|
|
| 223 |
visit '/projects/ecookbook/issues/new' |
|
| 224 | ||
| 225 |
page.execute_script(<<~JS) |
|
| 226 |
const RealDate = Date; |
|
| 227 |
window.Date = class extends RealDate {
|
|
| 228 |
constructor(...args) {
|
|
| 229 |
super(...(args.length ? args : [2026, 9, 19, 18, 3, 59])); |
|
| 230 |
} |
|
| 231 |
}; |
|
| 232 |
// 1x1 1-bit grayscale PNG image |
|
| 233 |
const png = Uint8Array.from(atob('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQAAAAA3bvkkAAAACklEQVR42mNgAAAAAgAB5Sfe/AAAAABJRU5ErkJggg=='), c => c.charCodeAt(0));
|
|
| 234 |
const clipboardData = new DataTransfer(); |
|
| 235 |
clipboardData.items.add(new File([png], 'image.png', { type: 'image/png' }));
|
|
| 236 |
const event = new Event('paste', { bubbles: true, cancelable: true });
|
|
| 237 |
Object.defineProperty(event, 'clipboardData', { value: clipboardData });
|
|
| 238 |
document.getElementById('issue_description').dispatchEvent(event);
|
|
| 239 |
window.Date = RealDate; |
|
| 240 |
JS |
|
| 241 |
filename = find('.attachments_fields input.filename').value
|
|
| 242 |
assert_match /\Aclipboard-20261019180359-[a-z0-9]{5}\.png\z/, filename
|
|
| 243 |
end |
|
| 244 | ||
| 220 | 245 |
def test_create_issue_with_new_target_version |
| 221 | 246 |
log_user('jsmith', 'jsmith')
|
| 222 | 247 | |