Skip to content

Commit 23735bb

Browse files
committed
Add test for previous and use getAttribute() to remove leading url
1 parent 3649b96 commit 23735bb

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/CaptureClicks.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ var CaptureClicks = React.createClass({
7272
}
7373

7474
// Ignore hash (used often instead of javascript:void(0) in strict CSP envs)
75-
if (el.href === '#' && !(this.props.environment instanceof HashEnvironment)) {
75+
if (el.getAttribute('href') === '#' && !(this.props.environment instanceof HashEnvironment)) {
7676
return;
7777
}
7878

tests/browser/browser.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ describe('Routing', function() {
127127
CaptureClicks({gotoURL: this.gotoURL},
128128
a({ref: 'anchor', href: '/__zuul/hi'}),
129129
a({ref: 'anchorUnhandled', href: '/goodbye'}),
130-
a({ref: 'anchorExternal', href: 'https://github.com/andreypopp/react-router-component'})
130+
a({ref: 'anchorExternal', href: 'https://github.com/andreypopp/react-router-component'}),
131+
a({ref: 'anchorPrevented', href: '#'})
131132
),
132133
Link({ref: 'outside', href: '/__zuul/hi'}),
133134
Link({ref: 'prevented', href: '/__zuul/hi', onClick: this.handlePreventedLinkClick}),
@@ -360,6 +361,20 @@ describe('Routing', function() {
360361
});
361362
clickOn(app.refs.anchorUnhandled);
362363
});
364+
365+
it('doesn\'t route bare hash links', function(done) {
366+
assertRendered('mainpage');
367+
var called = false;
368+
app.setProps({
369+
gotoURL: function(url) {
370+
called = true;
371+
done();
372+
}
373+
});
374+
clickOn(app.refs.anchorPrevented);
375+
assert(!called);
376+
done();
377+
});
363378
});
364379

365380
});

0 commit comments

Comments
 (0)