Skip to content

Commit

Permalink
Merge pull request #217 from whostolemyhat/ignore-querystrings
Browse files Browse the repository at this point in the history
Ignore querystrings
  • Loading branch information
epage committed May 12, 2017
2 parents 28df5e2 + 0a492b2 commit eb9e0b0
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main.rs
Expand Up @@ -375,7 +375,7 @@ fn build(config: &Config) {

fn static_file_handler(dest: &str, req: Request, mut res: Response) -> IoResult<()> {
// grab the requested path
let req_path = match req.uri {
let mut req_path = match req.uri {
RequestUri::AbsolutePath(p) => p,
_ => {
// return a 400 and exit from this request
Expand All @@ -386,6 +386,13 @@ fn static_file_handler(dest: &str, req: Request, mut res: Response) -> IoResult<
}
};

// strip off any querystrings so path.is_file() matches
// and doesn't stick index.html on the end of the path
// (querystrings often used for cachebusting)
if let Some(position) = req_path.rfind('?') {
req_path.truncate(position);
}

// find the path of the file in the local system
// (this gets rid of the '/' in `p`, so the `join()` will not replace the
// path)
Expand Down
12 changes: 12 additions & 0 deletions tests/fixtures/querystrings/_layouts/default.liquid
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<h1>{{ path }}</h1>

{{ content }}
</body>
</html>

10 changes: 10 additions & 0 deletions tests/fixtures/querystrings/_layouts/posts.liquid
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>My blog - {{ path }}</title>
</head>
<body>
{{ content }}
</body>
</html>

11 changes: 11 additions & 0 deletions tests/fixtures/querystrings/index.liquid
@@ -0,0 +1,11 @@
extends: default.liquid
---
This is my Index page!

{% for post in posts %}
<a href="{{post.path}}">{{ post.title }}</a>
{% endfor %}

{% for post in posts %}
<a href="{{post.path}}?v=123456">{{ post.title }}</a>
{% endfor %}
@@ -0,0 +1,8 @@
extends: posts.liquid

title: Querystrings
date: 9 May 2017 07:05:20 +0100
---
# {{ title }}

This asserts that files can be loaded with and without querystrings
5 changes: 5 additions & 0 deletions tests/mod.rs
Expand Up @@ -216,3 +216,8 @@ pub fn posts_in_subfolder() {
pub fn empty_frontmatter() {
run_test("empty_frontmatter").expect("Build error");
}

#[test]
pub fn querystrings() {
run_test("querystrings").expect("Build error");
}
21 changes: 21 additions & 0 deletions tests/target/querystrings/index.html
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<h1>index.html</h1>

This is my Index page!


<a href="posts/2014-08-24-my-first-blogpost.html">Querystrings</a>



<a href="posts/2014-08-24-my-first-blogpost.html?v=123456">Querystrings</a>


</body>
</html>

12 changes: 12 additions & 0 deletions tests/target/querystrings/posts/2014-08-24-my-first-blogpost.html
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title>My blog - posts/2014-08-24-my-first-blogpost.html</title>
</head>
<body>
<h1>Querystrings</h1>
<p>This asserts that files can be loaded with and without querystrings</p>

</body>
</html>

0 comments on commit eb9e0b0

Please sign in to comment.