defra_ruby_map 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/assets/javascripts/defra-ruby-map/map_init.js +7 -14
- data/app/controllers/defra_ruby_map/proxy_controller.rb +13 -2
- data/lib/defra_ruby_map/version.rb +1 -1
- data/vendor/assets/javascripts/defra-interactive-map/im-core.js +1 -1
- data/vendor/assets/javascripts/defra-interactive-map/im-core.js.LICENSE.txt +0 -30
- data/vendor/assets/javascripts/defra-interactive-map/index.js +1 -1
- data/vendor/assets/javascripts/defra-interactive-map/index.js.LICENSE.txt +0 -20
- data/vendor/assets/javascripts/interact-plugin/im-interact-plugin.js +1 -1
- data/vendor/assets/javascripts/interact-plugin/index.js +1 -1
- data/vendor/assets/javascripts/map-styles-plugin/im-map-styles-plugin.js +1 -1
- data/vendor/assets/javascripts/map-styles-plugin/index.js +1 -1
- data/vendor/assets/javascripts/maplibre-provider/im-maplibre-framework.js +1 -1
- data/vendor/assets/javascripts/maplibre-provider/im-maplibre-framework.js.LICENSE.txt +3 -3
- data/vendor/assets/javascripts/maplibre-provider/im-maplibre-provider.js +1 -1
- data/vendor/assets/javascripts/maplibre-provider/im-maplibre-worker.js +2 -0
- data/vendor/assets/javascripts/maplibre-provider/im-maplibre-worker.js.LICENSE.txt +4 -0
- data/vendor/assets/javascripts/maplibre-provider/index.js +1 -1
- data/vendor/assets/javascripts/proj4js/proj4.js +1 -1
- data/vendor/assets/javascripts/scale-bar-plugin/im-scale-bar-plugin.js +1 -1
- data/vendor/assets/javascripts/scale-bar-plugin/index.js +1 -1
- data/vendor/assets/javascripts/search-plugin/im-search-plugin.js +1 -1
- data/vendor/assets/javascripts/search-plugin/index.js +1 -1
- data/vendor/assets/stylesheets/defra-interactive-map/interactive-map.css +1 -1
- data/vendor/assets/stylesheets/defra-interactive-map/map-styles-plugin.css +1 -1
- data/vendor/assets/stylesheets/defra-interactive-map/scale-bar-plugin.css +1 -31
- data/vendor/assets/stylesheets/defra-interactive-map/search-plugin.css +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e8d9078473375bc26c9e8ed1dc672681d0cc2480beebe95d7b57416062bf8864
|
|
4
|
+
data.tar.gz: fe3aa53459ade42a9a4140fa3e0263431e24c6b91065fa8ec108315abb7204e5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 57b7d95465988b03bd267528fa0750649c63757fe03ed872517f0e2d09137d353a516c20ac9347d7d099c14c7877907c5e5490d57a15ab8a516e07115378e188
|
|
7
|
+
data.tar.gz: b5640a889bde939f5fd0fc45b72abf6ff7ebbbf123a4c22e0561b35252a167d2201656bb462161265f0d0d2a9d231a4a622e6e08c86d9700b705b67992696357
|
|
@@ -30,30 +30,23 @@
|
|
|
30
30
|
backgroundColor: "#f5f5f0"
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Maps OS Places API results to the search plugin's suggestion shape. The
|
|
39
|
-
// plugin renders `marked` via dangerouslySetInnerHTML, so the address text
|
|
40
|
-
// is HTML-escaped before the matched query is wrapped in <mark> — otherwise
|
|
41
|
-
// HTML in an OS address would execute (stored XSS).
|
|
33
|
+
// Maps OS Places API results to the search plugin's suggestion shape. Since
|
|
34
|
+
// v0.0.56 the plugin renders `marked` as text (only bare <mark> tags become
|
|
35
|
+
// elements), so the address must not be HTML-escaped or entities would show.
|
|
42
36
|
function parseOsPlacesResults(data, query) {
|
|
43
37
|
if (!data?.results) { return []; }
|
|
44
|
-
const
|
|
45
|
-
const matcher =
|
|
38
|
+
const queryPattern = (query || "").replace(/[.*+?^${}()|[\]\\]/g, String.raw`\$&`);
|
|
39
|
+
const matcher = queryPattern ? new RegExp(`(${queryPattern})`, "gi") : null;
|
|
46
40
|
return data.results.map(function (item) {
|
|
47
41
|
const record = item.DPA || item.LPI;
|
|
48
42
|
if (!record) { return null; }
|
|
49
43
|
const text = record.ADDRESS || "";
|
|
50
|
-
const safeText = escapeHtml(text);
|
|
51
44
|
const lng = record.LNG || 0;
|
|
52
45
|
const lat = record.LAT || 0;
|
|
53
46
|
return {
|
|
54
47
|
id: String(record.UPRN),
|
|
55
48
|
text: text,
|
|
56
|
-
marked: matcher ?
|
|
49
|
+
marked: matcher ? text.replace(matcher, "<mark>$1</mark>") : text,
|
|
57
50
|
point: [lng, lat],
|
|
58
51
|
bounds: [
|
|
59
52
|
lng - SUGGESTION_BOUNDS_PADDING,
|
|
@@ -270,6 +263,6 @@
|
|
|
270
263
|
|
|
271
264
|
window.DefraMap = {
|
|
272
265
|
init: initMap,
|
|
273
|
-
_internal: {
|
|
266
|
+
_internal: { parseOsPlacesResults: parseOsPlacesResults }
|
|
274
267
|
};
|
|
275
268
|
})();
|
|
@@ -77,16 +77,27 @@ module DefraRubyMap
|
|
|
77
77
|
headers["ETag"] = response["ETag"] if response["ETag"]
|
|
78
78
|
headers["Expires"] = response["Expires"] if response["Expires"]
|
|
79
79
|
end
|
|
80
|
-
render body: response.body, status: status_code,
|
|
80
|
+
render body: scrub_api_key(response.body), status: status_code,
|
|
81
81
|
content_type: response["Content-Type"] || "application/octet-stream"
|
|
82
82
|
end
|
|
83
83
|
|
|
84
|
+
# OS echoes the key back in relayed bodies (e.g. the VTS "tiles" URLs and the style's
|
|
85
|
+
# sprite/glyphs/source URLs). Drop the key param so the browser never sees it
|
|
86
|
+
def scrub_api_key(body)
|
|
87
|
+
return body if body.blank? || body.exclude?(os_maps_api_key)
|
|
88
|
+
|
|
89
|
+
escaped_key = Regexp.escape(os_maps_api_key)
|
|
90
|
+
body.gsub(/(\?|&|\\u0026)key=#{escaped_key}((?:&|\\u0026)?)/) do
|
|
91
|
+
Regexp.last_match(2).empty? ? "" : Regexp.last_match(1)
|
|
92
|
+
end.gsub(os_maps_api_key, "")
|
|
93
|
+
end
|
|
94
|
+
|
|
84
95
|
def proxy_get(base_url, params)
|
|
85
96
|
uri = URI(base_url)
|
|
86
97
|
uri.query = URI.encode_www_form(params)
|
|
87
98
|
|
|
88
99
|
response = fetch_upstream(uri)
|
|
89
|
-
render(json: response.body, status: response.code.to_i)
|
|
100
|
+
render(json: scrub_api_key(response.body), status: response.code.to_i)
|
|
90
101
|
rescue StandardError => e
|
|
91
102
|
Rails.logger.error("[DefraRubyMap] #{action_name} upstream error: #{e.class}: #{e.message}")
|
|
92
103
|
render(json: { error: "upstream service unavailable" }, status: :bad_gateway)
|