Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Here's fixes for a couple of small bugs I found. #17

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/RuleMatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ var RuleMatcher = function(rules){
this.rules = rules;

this.redirectOnMatch = function(request){
var rule = _.find(rules, function(rule){
return rule.isActive
&& request.url.indexOf(rule.from) > -1
&& request.requestId !== lastRequestId;
var rule = _.find(rules, function(rule){
// Don't match user/pat/query parts of URL
var url = new URL(request.url);
url.username='';
url.password='';
url.pathname='';
url.search='';
return rule.isActive
&& url.toString().indexOf(rule.from) > -1
&& request.requestId !== lastRequestId;
});

if(rule){
Expand Down
4 changes: 4 additions & 0 deletions src/RulesService.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
var LocalRulesService = function (){
this.get = function(){
if (typeof localStorage['rules'] === 'undefined' || localStorage['rules'] === 'undefined'){
localStorage['rules'] = JSON.stringify([]);
}

return JSON.parse(localStorage['rules']);
};
this.set = function(data){
Expand Down
2 changes: 1 addition & 1 deletion src/switcheroo.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<p ng-if="!rules.length" id="no-rules">
You have no redirect rules at the moment so why don't you go ahead and <em class="switcheroo">Switcheroo</em>.
</p>
<ul id="rules" ng-repeat="rule in rules">
<ul id="rules" ng-repeat="rule in rules track by $index">
<li>
<span class="from" ng-if="!isEditing" title="{{rule.from}}">{{shortenText(rule.from)}}</span>
<input type="text" ng-if="isEditing" ng-model="rule.from" />
Expand Down