Skip to content

Commit

Permalink
Fix #732: the wiki urls should encode file names
Browse files Browse the repository at this point in the history
Also remove qualifiers (#xxx) when checking extensions and file types
  • Loading branch information
gnodet committed Nov 7, 2013
1 parent 975f00b commit 927099c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
24 changes: 15 additions & 9 deletions hawtio-git/src/main/java/io/hawt/git/FileInfo.java
Expand Up @@ -23,16 +23,22 @@ public class FileInfo {
public static FileInfo createFileInfo(File rootDir, File file) {
String path = getRelativePath(rootDir, file).replace("\\", "/");
FileInfo answer = new FileInfo(path, file.getName(), file.lastModified(), file.length(), file.isDirectory());
if (file.isFile() && file.getName().endsWith(".xml")) {
// lets load the XML namespaces
try {
Set<String> uris = XmlHelper.getNamespaces(file);
if (uris.size() > 0) {
String[] namespaces = uris.toArray(new String[uris.size()]);
answer.setXmlNamespaces(namespaces);
if (file.isFile()) {
String name = file.getName();
if (name.indexOf('#') > 0) {
name = name.substring(0, name.indexOf('#'));
}
if (name.endsWith(".xml")) {
// lets load the XML namespaces
try {
Set<String> uris = XmlHelper.getNamespaces(file);
if (uris.size() > 0) {
String[] namespaces = uris.toArray(new String[uris.size()]);
answer.setXmlNamespaces(namespaces);
}
} catch (Exception e) {
LOG.warn("Failed to parse the XML namespaces in " + file + " due: " + e.getMessage() + ". This exception is ignored.", e);
}
} catch (Exception e) {
LOG.warn("Failed to parse the XML namespaces in " + file + " due: " + e.getMessage() + ". This exception is ignored.", e);
}
}
return answer;
Expand Down
2 changes: 1 addition & 1 deletion hawtio-web/src/main/webapp/app/wiki/js/edit.ts
Expand Up @@ -112,7 +112,7 @@ module Wiki {
function goToView() {
var path = Core.trimLeading($scope.viewLink(), "#");
console.log("going to view " + path);
$location.path(path);
$location.path(Wiki.decodePath(path));
console.log("location is now " + $location.path());
}

Expand Down
16 changes: 13 additions & 3 deletions hawtio-web/src/main/webapp/app/wiki/js/helpers.ts
Expand Up @@ -145,7 +145,7 @@ module Wiki {
var link = null;
var start = startLink(branch);
if (pageId) {
link = start + "/view/" + Core.trimLeading(pageId, "/");
link = start + "/view/" + encodePath(Core.trimLeading(pageId, "/"));
} else {
// lets use the current path
var path = $location.path();
Expand All @@ -168,7 +168,7 @@ module Wiki {
var link = null;
var start = startLink(branch);
if (pageId) {
link = start + "/edit/" + pageId;
link = start + "/edit/" + encodePath(pageId);
} else {
// lets use the current path
var path = $location.path();
Expand All @@ -182,7 +182,7 @@ module Wiki {
var start = startLink(branch);
var link = null;
if (pageId) {
link = start + "/create/" + pageId;
link = start + "/create/" + encodePath(pageId);
} else {
// lets use the current path
link = "#" + path.replace(/(view|edit|formTable)/, "create");
Expand All @@ -196,6 +196,14 @@ module Wiki {
return link;
}

export function encodePath(pageId:string) {
return pageId.split("/").map(encodeURIComponent).join("/");
}

export function decodePath(pageId:string) {
return pageId.split("/").map(decodeURIComponent).join("/");
}

export function fileFormat(name:string, fileExtensionTypeRegistry) {
var extension = fileExtension(name);
var answer = null;
Expand Down Expand Up @@ -355,6 +363,8 @@ module Wiki {
}

export function fileExtension(name) {
if (name.indexOf('#') > 0)
name = name.substring(0, name.indexOf('#'));
return Core.fileExtension(name, "markdown");
}

Expand Down
2 changes: 1 addition & 1 deletion hawtio-web/src/main/webapp/app/wiki/js/navbar.ts
Expand Up @@ -60,7 +60,7 @@ module Wiki {
if (!name.startsWith("/") && !href.endsWith("/")) {
href += "/";
}
href += name;
href += Wiki.encodePath(name);
if (!name.isBlank()) {
$scope.breadcrumbs.push({href: href, name: name});
}
Expand Down
2 changes: 1 addition & 1 deletion hawtio-web/src/main/webapp/app/wiki/js/view.ts
Expand Up @@ -107,7 +107,7 @@ module Wiki {
var start = startLink($scope.branch);
var prefix = start + "/view";
var postFix = "";
var path = child.path;
var path = Wiki.encodePath(child.path);
if (child.directory) {
// if we are a folder with the same name as a form file, lets add a form param...
var formPath = path + ".form";
Expand Down

0 comments on commit 927099c

Please sign in to comment.