From afcdae37b3184eac69de8f0871bae12131769608 Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Sun, 19 Jan 2014 02:02:36 +0100 Subject: [PATCH] Fixed nextpattern to js value conversion (#62). The prev- and nextpatterns can't be given to JavaScript as strings that are split on the ',' to be interpreted as regular expression. So the patterns have to be given as array of RegExp objects instead. --- src/hints.c | 9 +++++++-- src/hints.js | 3 +-- src/js.c | 13 +++++++++++++ src/js.h | 1 + 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/hints.c b/src/hints.c index 52fe9e0..9b58bd3 100644 --- a/src/hints.c +++ b/src/hints.c @@ -161,13 +161,18 @@ void hints_fire(void) void hints_follow_link(const gboolean back, int count) { - char *pattern = back ? vb.config.prevpattern : vb.config.nextpattern; + char *json = g_strdup_printf( + "[%s]", + back ? vb.config.prevpattern : vb.config.nextpattern + ); JSValueRef arguments[] = { js_string_to_ref(hints.ctx, back ? "prev" : "next"), - js_string_to_ref(hints.ctx, pattern), + js_object_to_ref(hints.ctx, json), JSValueMakeNumber(hints.ctx, count) }; + g_free(json); + call_hints_function("followLink", 3, arguments); } diff --git a/src/hints.js b/src/hints.js index 8a0ac78..cb4a503 100644 --- a/src/hints.js +++ b/src/hints.js @@ -429,8 +429,7 @@ Object.freeze((function(){ } /* follow the count last link on pagematching the given regex list */ - function followLink(rel, list, count) { - var patterns = list.split(","); + function followLink(rel, patterns, count) { /* returns array of matching elements */ function followFrame(frame) { var i, p, reg, res = [], diff --git a/src/js.c b/src/js.c index cd8e6a0..c54c613 100644 --- a/src/js.c +++ b/src/js.c @@ -158,6 +158,19 @@ JSValueRef js_string_to_ref(JSContextRef ctx, const char *string) return ref; } +/** + * Retrieves a values reference for given json or array string string. + */ +JSValueRef js_object_to_ref(JSContextRef ctx, const char *json) +{ + JSValueRef ref = NULL; + if (evaluate_string(ctx, json, NULL, &ref)) { + return ref; + } + g_warning("Could not parse %s", json); + return NULL; +} + /** * Runs a string as JavaScript and returns if the call succeed. * In case the call succeed, the given *result is filled with the result diff --git a/src/js.h b/src/js.h index 7ab81c8..491fc50 100644 --- a/src/js.h +++ b/src/js.h @@ -30,5 +30,6 @@ char* js_object_call_function(JSContextRef ctx, JSObjectRef obj, const char *func, int count, JSValueRef params[]); char *js_ref_to_string(JSContextRef ctx, JSValueRef ref); JSValueRef js_string_to_ref(JSContextRef ctx, const char *string); +JSValueRef js_object_to_ref(JSContextRef ctx, const char *json); #endif /* end of include guard: _JS_H */ -- 2.20.1