Skip to content
Open
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
27 changes: 21 additions & 6 deletions lib/helpers.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ exports.escapeValue = (object) ->
if (typeof object == "string")
return "\"" + object.replace("\\","\\\\").replace("\"","\\\"") + "\""
return object;

exports.escapeHtml = (string) ->
entityMap = {
"<": "&lt;"
Expand Down Expand Up @@ -66,26 +66,31 @@ exports.deserializeArray = (array) ->
exports.localPathToRemote = (localPath) ->
pathMaps = atom.config.get('php-debug.PathMaps')
for pathMap in pathMaps
remote = pathMap.substring(0,pathMap.indexOf(";"))
local = pathMap.substring(pathMap.indexOf(";")+1)
remote = fixPath(pathMap.substring(0,pathMap.indexOf(";")))
local = fixPath(pathMap.substring(pathMap.indexOf(";")+1))
if localPath.indexOf(local) == 0
path = localPath.replace(local, remote)
if remote.indexOf('/') != null
# remote path appears to be a unix path, so replace any \'s with /'s'
path = path.replace(/\\/g, '/')
else if remote.indexOf('\\') != null
# This might not work in some cases
# remote path appears to be a windows path, so replace any /'s with \'s'
path = path.replace(/\//g, '\\')
else
atom.notifications.addError "Oops, looks like php-debug can't determine the remote path's type"
return path.replace('file://','')
return localPath.replace('file://','')

exports.remotePathToLocal = (remotePath) ->
pathMaps = atom.config.get('php-debug.PathMaps')
remotePath = decodeURI(remotePath)
for pathMap in pathMaps
remote = pathMap.substring(0,pathMap.indexOf(";"))
local = pathMap.substring(pathMap.indexOf(";")+1)
remote = fixPath(pathMap.substring(0,pathMap.indexOf(";")))
local = fixPath(pathMap.substring(pathMap.indexOf(";")+1))
if remotePath.indexOf('/') != null && remotePath.indexOf('/') != 0
#Consider throwing an error instead of modifying invalid input
#can check with require('path').posix.isAbsolute()
adjustedPath = '/' + remotePath
if adjustedPath.indexOf(remote) == 0
return adjustedPath.replace(remote, local)
Expand All @@ -94,5 +99,15 @@ exports.remotePathToLocal = (remotePath) ->
if remotePath.indexOf(remote) == 0
return remotePath.replace(remote, local)
break

return remotePath.replace('file://','')

#Get rid of extra slashes and trailing slashes
#Both of them give us a hard time
fixPath = (path) ->
modpath = require 'path'
path = modpath.normalize(path)
lastChar = path.slice(-1)
if lastChar == '/' || lastChar == '\\'
return path.slice(0, path.length - 1)
return path