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

Path not recognized when paramater is substring of path #35

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
6 changes: 4 additions & 2 deletions path.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ var Path = {
for (i = 0; i < slice.split("/").length; i++) {
if ((i < compare.split("/").length) && (slice.split("/")[i].charAt(0) === ":")) {
params[slice.split('/')[i].replace(/:/, '')] = compare.split("/")[i];
compare = compare.replace(compare.split("/")[i], slice.split("/")[i]);
var compare_array = compare.split("/");
compare_array[i] = slice.split("/")[i];
compare = compare_array.join("/");
}
}
}
Expand Down Expand Up @@ -177,7 +179,7 @@ Path.core.route.prototype = {
if (Path.routes.defined[this.path].hasOwnProperty("do_enter")) {
if (Path.routes.defined[this.path].do_enter.length > 0) {
for (i = 0; i < Path.routes.defined[this.path].do_enter.length; i++) {
result = Path.routes.defined[this.path].do_enter[i].apply(this, null);
result = Path.routes.defined[this.path].do_enter[i].apply(this);
if (result === false) {
halt_execution = true;
break;
Expand Down
34 changes: 20 additions & 14 deletions tests/path.js.test.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@
<html>
<head>
<title>PathJS Test</title>
<script type="text/javascript" src="../path.js"></script>
<script type="text/javascript" src="path.js"></script>
<script type="text/javascript">
var hrefs = [
"#A",
"#A",
"#B",
"#C",
"#D1",
"#D2",
"#D2",
"#E/params/1/parse",
"#E/params/2/parse",
"#E/params/3/check",
"#F",
"#G",
"#H",
"#H/10",
"#H/10/20"
"#I/I",
"#H",
"#H/10",
"#H/10/20"
];
var index = 0;
var timer = null;
Expand Down Expand Up @@ -115,11 +116,15 @@
update("G[action - NOT HIT]");
});

Path.map("#H(/:id_one)(/:id_two)").to(function(){
var id_one = this.params["id_one"] || "N/A";
var id_two = this.params["id_two"] || "N/A";
update("H(one=" + id_one + ", two=" + id_two + ")");
});
Path.map("#H(/:id_one)(/:id_two)").to(function(){
var id_one = this.params["id_one"] || "N/A";
var id_two = this.params["id_two"] || "N/A";
update("H(one=" + id_one + ", two=" + id_two + ")");
});

Path.map("#I(/:id)").to(function(){
update("I[action](parse id=" + this.params['id'] + ")");
});

Path.rescue(function(){
update("RESCUE");
Expand Down Expand Up @@ -173,19 +178,20 @@ <h2>Test Suite</h2>
<tr><td>G[enter 2]</td> <td>Second enter method of G</td></tr>
<tr><td>G[enter 3]</td> <td>Third enter method of G</td></tr>
<tr><td>G[enter 4]</td> <td>Last enter method of G - Returns false, stops execution</td></tr>
<tr><td>I(I=I)</td> <td>Testing functionaltiy for paramaters containing route name</td></tr>
<tr><td>H(one=N/A, two=N/A)</td> <td>Optional parameters with only the require part submitted</td></tr>
<tr><td>H(one=10, two=N/A)</td> <td>Optional parameters with one optional part submitted</td></tr>
<tr><td>H(one=10, two=20)</td> <td>Optional parameters two levels deep</td></tr>
<tr><td>H(one=10, two=N/A)</td> <td>Testing "back" functionality</td></tr>
<tr><td>H(one=10, two=N/A)</td> <td>Testing "back" functionality</td></tr>
</table>
</div><br /><br />
<div id="console">
<h3>Expected</h3>
<div id="expected">F[enter]::F[action]::A[enter]::A[action]::A[exit]::B[enter]::B[action]::C[action]::C[exit]::RESCUE::RESCUE::E[enter](parse id=1)::E[action](parse id=1)::E[enter](parse id=2)::E[action](parse id=2)::E[action](check id=3)::E[exit](check id=3)::F[enter]::F[action]::G[enter 1]::G[enter 2]::G[enter 3]::G[enter 4]::H(one=N/A, two=N/A)::H(one=10, two=N/A)::H(one=10, two=20)::H(one=10, two=N/A)</div>
<div id="expected">F[enter]::F[action]::A[enter]::A[action]::A[exit]::B[enter]::B[action]::C[action]::C[exit]::RESCUE::RESCUE::E[enter](parse id=1)::E[action](parse id=1)::E[enter](parse id=2)::E[action](parse id=2)::E[action](check id=3)::E[exit](check id=3)::F[enter]::F[action]::G[enter 1]::G[enter 2]::G[enter 3]::G[enter 4]::I[action](parse id=I)::H(one=N/A, two=N/A)::H(one=10, two=N/A)::H(one=10, two=20)::H(one=10, two=N/A)</div>
<h3>Actual</h3>
<div id="actual"></div>
<h3>Grade</h3>
<div id="grade"></div>
</div>
</body>
</html>
</html>