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

Proxy regexp too aggressive #138

Closed
simonburger opened this issue Apr 15, 2014 · 4 comments
Closed

Proxy regexp too aggressive #138

simonburger opened this issue Apr 15, 2014 · 4 comments

Comments

@simonburger
Copy link

I'm having issues with urls that look like http://example.com/sites/example.com/theme/style.css being rewritten to http://192.168.0.24:3002/sites/192.168.0.24:3002/theme/style.css
In proxy.js utils.rewriteLinks is using a global regular expression match. Can we make this just stop after the first match please?

@shakyShane
Copy link
Contributor

Oh yeah - good catch! In the spirit of trying encourage more contributors, would you like to make a PR with some failing tests? (and a fix, if you can).

As a pointer, in test/specs/proxy/proxy.utils.js in the first describe block you could test the regex like this.

    // run 'npm test' to see everything still passes
    // This will pass
    it("should use the regex to replace links", function () {
        var rewrite = utils.rewriteLinks({host: "example.com", port: 80}, proxyUrl);
        var actual = "<a href='http://example.com'></a>".replace(rewrite.match, rewrite.fn);
        var expected = "<a href='http://192.168.0.4:3002'></a>";
        assert.equal(actual, expected);
    });

And then to replicate your issue, something like this should cause it to fail

    // This will fail - time to fix
    it("should use the regex to replace links", function () {
        var rewrite  = utils.rewriteLinks({host: "example.com", port: 80}, proxyUrl);
        var actual = "<a href='http://example.com/sites/example.com/about'></a>".replace(rewrite.match, rewrite.fn);
        var expected = "<a href='http://192.168.0.4:3002/sites/example.com/about'></a>";
        assert.equal(actual, expected);
    });

To run the tests, just fork the repo, clone it locally to your machine, run npm install and then run npm test to run the linting + tests.

Let me know if you have any problems, or if you would rather not help out :)

@simonburger
Copy link
Author

Ok, cool. I might need a few weeks to get onto this, but I'll give it a shot.

@shakyShane
Copy link
Contributor

I have this so far - seems to work, but seems to complicated

http://regexr.com/38nl6

@shakyShane
Copy link
Contributor

fixed in 0.8.1 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants