From 34233193cba4bf1b0e91f3210660e20fc58e0be8 Mon Sep 17 00:00:00 2001
From: Patrick Steinhardt <ps@pks.im>
Date: Sat, 20 May 2017 10:36:40 +0200
Subject: [PATCH] setting: always clear scripts previous to adding global ones

Previous to adding user scripts to the content manager, we should always
clear existing scripts. Otherwise, e.g. in the sequence

    :set user-scripts=off
    :set user-scripts=on

we'd end up with the same global scripts injected twice.

Fix the issue by unconditionally clearing all user scripts previous to
adding scripts.
---
 src/setting.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/setting.c b/src/setting.c
index de33832..ee7cb19 100644
--- a/src/setting.c
+++ b/src/setting.c
@@ -607,6 +607,7 @@ static int user_scripts(Client *c, const char *name, DataType type, void *value,
     gboolean enabled = *(gboolean*)value;
 
     ucm = webkit_web_view_get_user_content_manager(c->webview);
+    webkit_user_content_manager_remove_all_scripts(ucm);
 
     if (enabled) {
         if (vb.files[FILES_SCRIPT]
@@ -621,8 +622,6 @@ static int user_scripts(Client *c, const char *name, DataType type, void *value,
             webkit_user_script_unref(script);
             g_free(source);
         }
-    } else {
-        webkit_user_content_manager_remove_all_scripts(ucm);
     }
 
     /* Inject the global scripts. */
-- 
2.20.1