Error message when cancelling a label creation

When "Create label" menu is clicked, a popup asks for the label name. If the Cancel button is immediately entered, an error message is displayed: TypeError: can't access property "trim", caption is null.

Indeed, the JavaScript prompt() message returns null when Cancel is pressed. The test "caption !== undefined" is thus true, and the trim() is tried on null, which fails.

The fix is to only check for "caption" or "caption != null".
This commit is contained in:
LaurentGH 2025-11-05 17:07:35 +01:00 committed by GitHub
parent fc4cfb9d10
commit 4da5e11653
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -325,7 +325,7 @@ const CommonDialogs = {
addLabel: function() {
const caption = prompt(__("Please enter label caption:"), "");
if (caption !== undefined && caption.trim().length > 0) {
if (caption && caption.trim().length > 0) {
const query = {op: "Pref_Labels", method: "add", caption: caption.trim()};