From 7837da1001f466cfc709c5b8eefaf6b1e4021498 Mon Sep 17 00:00:00 2001 From: Runrioter Date: Sun, 4 Mar 2018 02:28:21 +0800 Subject: [PATCH] refactor: use native url lib --- helpers.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/helpers.js b/helpers.js index 1ff994f..cfadd37 100644 --- a/helpers.js +++ b/helpers.js @@ -1,8 +1,9 @@ -exports.pathMatch = pathMatch; +var parse = require('url').parse; -function pathMatch(url, path) { - if (url == path) return true; - var q = url.indexOf('?'); - if (q == -1) return false; - return url.substring(0, q) == path; +exports.pathMatch = function(url, path) { + try { + return parse(url).pathname === path; + } catch (e) { + return false; + } }