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

Disable json escape #62

Merged
merged 4 commits into from
Sep 29, 2023
Merged
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
18 changes: 18 additions & 0 deletions .github/workflows/tidy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: tidy
on:
push:
branches:
- master
pull_request:
permissions:
contents: read
jobs:
tidy:
name: tidy
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v4
with:
go-version: '1.20'
- uses: actions/checkout@v3
- uses: katexochen/go-tidy-check@v2
2 changes: 1 addition & 1 deletion assets/i18n/active.nl.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pagina's om te zien welke zoomniveaus door deze API worden ondersteund."""

# Conformance page
ConformanceAbstract = """
Hieronder staan verwijzingen naar de OGC API conformiteitsklassen waaraan deze service voldoet. <br/>De statuskolom geeft aan of de betreffende specificatie reeds tot officiele standaard is verklaard door het OGC."""
Hieronder staan verwijzingen naar de OGC API conformiteitsklassen waaraan deze service voldoet. <br/>De statuskolom geeft aan of de betreffende specificatie reeds tot officiële standaard is verklaard door het OGC."""
Standard = "Standaard"
Draft = "Concept"

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572
github.com/gomarkdown/markdown v0.0.0-20230322041520-c84983bdbf2a
github.com/nicksnyder/go-i18n/v2 v2.2.1
github.com/sqids/sqids-go v0.4.1
github.com/stretchr/testify v1.8.2
github.com/urfave/cli/v2 v2.25.3
github.com/writeas/go-strip-markdown/v2 v2.1.1
Expand All @@ -36,7 +37,6 @@ require (
github.com/perimeterx/marshmallow v1.1.4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sqids/sqids-go v0.4.1 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/sys v0.8.0 // indirect
Expand Down
3 changes: 1 addition & 2 deletions ogc/features/domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ func (c EncodedCursor) Decode() int64 {
if len(decodedValue) > 1 {
log.Printf("encountered more than one cursor value after decoding: '%v', "+
"this is not allowed! Defaulting to first value.", decodedValue)
}
if len(decodedValue) == 0 {
} else if len(decodedValue) == 0 {
log.Printf("decoding cursor value '%v' failed, defaulting to first page", decodedValue)
return 0
}
Expand Down
16 changes: 14 additions & 2 deletions ogc/features/json.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package features

import (
"bytes"
"encoding/json"
"fmt"
"net/http"
Expand All @@ -23,7 +24,7 @@ func (jf *jsonFeatures) featuresAsGeoJSON(w http.ResponseWriter, collectionID st
cursor domain.Cursor, limit int, fc *domain.FeatureCollection) {

fc.Links = jf.createFeatureCollectionLinks(collectionID, cursor, limit)
fcJSON, err := json.Marshal(&fc)
fcJSON, err := toJSON(&fc)
if err != nil {
http.Error(w, "Failed to marshal FeatureCollection to JSON", http.StatusInternalServerError)
return
Expand All @@ -33,7 +34,7 @@ func (jf *jsonFeatures) featuresAsGeoJSON(w http.ResponseWriter, collectionID st

func (jf *jsonFeatures) featureAsGeoJSON(w http.ResponseWriter, collectionID string, feat *domain.Feature) {
feat.Links = jf.createFeatureLinks(collectionID, feat.ID)
featJSON, err := json.Marshal(feat)
featJSON, err := toJSON(feat)
if err != nil {
http.Error(w, "Failed to marshal Feature to JSON", http.StatusInternalServerError)
return
Expand Down Expand Up @@ -108,3 +109,14 @@ func (jf *jsonFeatures) createFeatureLinks(collectionID string, featureID string
})
return links
}

// toJSON performs the equivalent of json.Marshal but without escaping '<', '>' and '&'.
// Especially the '&' is important since we use this character in the next/prev links.
func toJSON(input interface{}) ([]byte, error) {
buffer := &bytes.Buffer{}
encoder := json.NewEncoder(buffer)
encoder.SetEscapeHTML(false)
err := encoder.Encode(input)
marshalled := bytes.TrimRight(buffer.Bytes(), "\n")
return marshalled, err
}
Loading