xiongtong3 / switchy

Automatically exported from code.google.com/p/switchy
0 stars 0 forks source link

wrong parse method for AutoProxy list (with bug fixed method) #239

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
the detail can be seen here: 
http://code.google.com/p/switchy/issues/detail?id=149

i just look over the source and find where is the problem and how this problem 
occur.
file assets\scripts\ruleManager.js, line 847.
the regular expression is wrong. 
yes, if you use any regexp software to test this expression and you will get 
expected result, and maybe author think it's done like it being written.
however, i don't know who's fault, in fact it won't match the expected url.
the correct expression is "^(?:[^\\w]+\\.)?" instead of author's 
"^[\\w\\-]+:\\/+(?!\\/)(?:[^\\/]+\\.)?"
after modification, the AutoProxy list works quite well~
i hope author can merge my code or use optimised code in the newer version

Original issue reported on code.google.com by ayanamist on 25 Oct 2010 at 7:13

GoogleCodeExporter commented 9 years ago
found an easy way. may be author misuse something, just add slashes to double 
like "^[\\w\\-]+:\\/+(?!\\/)(?:[^\\/]+\\.)?" to 
"^[\\\\w\\-]+:\\\\/+(?!\\\\/)(?:[^\\\\/]+\\\\.)?"

also since some rule of autoproxy-list start with a plus which can't be 
recognize by Switchy, you should trim it first.

add these codes after line 829:
if (line[0] == '+') {
line = line.substring(1);
}

Original comment by ayanamist on 29 Oct 2010 at 9:23

GoogleCodeExporter commented 9 years ago
just upload a modified version to help people who dont know how to modify

Original comment by ayanamist on 29 Oct 2010 at 5:49

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks a lot~

Original comment by yangji...@gmail.com on 30 Oct 2010 at 7:13

GoogleCodeExporter commented 9 years ago
find another method to test whether rule is valid or not to avoid problem.
ruleManager.js after line 333 insert code below:

    // just declare to see whether regular expression rule is valid
    if (rule.patternType == RuleManager.PatternTypes.regexp) {
        try {
            var tmp = new RegExp(rule.urlPattern);
        }
        catch(e) {
            delete tmp;
            return '';
        }
        delete tmp;
    }

also give out a modified version to help noob.

you need to unintall previous Switchy and install this one. sorry i dont save 
my pem file before.
YOU SHOULD USE BACKUP/RESTORE FUNCTION TO SAVE YOUR OPTIONS!!!

Original comment by ayanamist on 31 Oct 2010 at 10:58

Attachments:

GoogleCodeExporter commented 9 years ago
just modify something else to optimize my code. here is the latest version.
because code is messy, you can unzip the crx file and diff them. only 
RuleManager.js is modified.

Original comment by ayanamist on 31 Oct 2010 at 11:19

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for Ayanamist's work!!
It is very nice!!
I hope this update will merge in next release.

Original comment by fuaiqi...@gmail.com on 28 Dec 2010 at 8:04