Skip to content

Commit

Permalink
Take more care on preserving and honoring spaces and caps in object n…
Browse files Browse the repository at this point in the history
…ames. Closes #105
  • Loading branch information
pramsey committed Feb 4, 2022
1 parent 51efee5 commit 33ce1e8
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
3 changes: 2 additions & 1 deletion layer.go
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"net/http"
"net/url"
)

// LayerType is the table/function type of a layer
Expand Down Expand Up @@ -103,7 +104,7 @@ func getJSONLayers(r *http.Request) map[string]layerJSON {
Name: v.GetName(),
Schema: v.GetSchema(),
Description: v.GetDescription(),
DetailURL: fmt.Sprintf("%s/%s.json", urlBase, v.GetID()),
DetailURL: fmt.Sprintf("%s/%s.json", urlBase, url.PathEscape(v.GetID())),
}
}
return json
Expand Down
8 changes: 4 additions & 4 deletions layer_proc.go
Expand Up @@ -152,7 +152,7 @@ func (lyr *LayerFunction) getFunctionDetailJSON(req *http.Request) (FunctionDeta
MaxZoom: viper.GetInt("DefaultMaxZoom"),
}
// TileURL is relative to server base
td.TileURL = fmt.Sprintf("%s/%s/{z}/{x}/{y}.pbf", serverURLBase(req), lyr.ID)
td.TileURL = fmt.Sprintf("%s/%s/{z}/{x}/{y}.pbf", serverURLBase(req), url.PathEscape(lyr.ID))

tmpMap := make(map[int]FunctionArgument)
tmpKeys := make([]int, 0, len(lyr.Arguments))
Expand All @@ -174,8 +174,8 @@ func getFunctionLayers() ([]LayerFunction, error) {
layerSQL := `
SELECT
Format('%s.%s', n.nspname, p.proname) AS id,
n.nspname,
p.proname,
n.nspname AS nspname,
p.proname AS proname,
coalesce(d.description, '') AS description,
coalesce(p.proargnames, ARRAY[]::text[]) AS argnames,
coalesce(string_to_array(oidvectortypes(p.proargtypes),', '), ARRAY[]::text[]) AS argtypes,
Expand All @@ -187,7 +187,7 @@ func getFunctionLayers() ([]LayerFunction, error) {
AND p.proargnames[1:3] = ARRAY['z'::text, 'x'::text, 'y'::text]
AND prorettype = 17
AND has_schema_privilege(n.oid, 'usage')
AND has_function_privilege(Format('%s.%s(%s)', n.nspname, p.proname, oidvectortypes(proargtypes)), 'execute')
AND has_function_privilege(Format('%s.%s(%s)', quote_ident(n.nspname), quote_ident(p.proname), oidvectortypes(proargtypes)), 'execute')
ORDER BY 1
`

Expand Down
2 changes: 1 addition & 1 deletion layer_table.go
Expand Up @@ -216,7 +216,7 @@ func (lyr *LayerTable) getTableDetailJSON(req *http.Request) (TableDetailJSON, e
MaxZoom: viper.GetInt("DefaultMaxZoom"),
}
// TileURL is relative to server base
td.TileURL = fmt.Sprintf("%s/%s/{z}/{x}/{y}.pbf", serverURLBase(req), lyr.ID)
td.TileURL = fmt.Sprintf("%s/%s/{z}/{x}/{y}.pbf", serverURLBase(req), url.PathEscape(lyr.ID))

// Want to add the properties to the Json representation
// in table order, which is fiddly
Expand Down
4 changes: 2 additions & 2 deletions main.go
Expand Up @@ -279,7 +279,7 @@ func requestListJSON(w http.ResponseWriter, r *http.Request) error {
log.WithFields(log.Fields{
"event": "request",
"topic": "layerlist",
}).Trace("requestListJson")
}).Trace("requestListJSON")
// Update the global in-memory list from
// the database
if err := loadLayers(); err != nil {
Expand All @@ -296,7 +296,7 @@ func requestDetailJSON(w http.ResponseWriter, r *http.Request) error {
log.WithFields(log.Fields{
"event": "request",
"topic": "layerdetail",
}).Tracef("requestDetailJson(%s)", lyrID)
}).Tracef("requestDetailJSON(%s)", lyrID)

// Refresh the layers list
if err := loadLayers(); err != nil {
Expand Down

0 comments on commit 33ce1e8

Please sign in to comment.