From 63afb63061e009774736b470b1216076fe0a3089 Mon Sep 17 00:00:00 2001 From: Sam Matthews Date: Thu, 2 Feb 2023 13:05:36 -0800 Subject: [PATCH] 2.0.2 (#134) * bug fix: exact match on worldview and class fields * 2.0.2-dev.1 * [publish binary] * 2.0.2 [publish binary] --------- Co-authored-by: lily-chai --- CHANGELOG.md | 4 ++++ package-lock.json | 4 ++-- package.json | 2 +- src/vtcomposite.cpp | 8 ++++---- test/vtcomposite-localize-class.test.js | 8 +++++--- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9eeface..609a448 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 2.0.2 + +- Fixes a bug in `localize` where the class and worldview key prefixes were true for soft matches, which unintentionally filters out features where `class = class*`. Now the logic uses an exact match so `class != classes`. [#134](https://github.com/mapbox/vtcomposite/pull/134) + # 2.0.1 - Fixes a bug in `localize` function that throws an error when languages or worldviews is an empty array [#131](https://github.com/mapbox/vtcomposite/pull/131) diff --git a/package-lock.json b/package-lock.json index 33c0384..18a5888 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@mapbox/vtcomposite", - "version": "2.0.1", + "version": "2.0.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@mapbox/vtcomposite", - "version": "2.0.1", + "version": "2.0.2", "hasInstallScript": true, "license": "ISC", "dependencies": { diff --git a/package.json b/package.json index 8c7ee8c..d87b867 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@mapbox/vtcomposite", - "version": "2.0.1", + "version": "2.0.2", "description": "Compositing operations on Vector Tiles (c++ bindings using N-API)", "url": "http://github.com/mapbox/vtcomposite", "main": "./lib/index.js", diff --git a/src/vtcomposite.cpp b/src/vtcomposite.cpp index 00b5ef4..adedcf8 100644 --- a/src/vtcomposite.cpp +++ b/src/vtcomposite.cpp @@ -742,8 +742,8 @@ struct LocalizeWorker : Napi::AsyncWorker std::string property_key = property.key().to_string(); if ( - utils::startswith(property_key, baton_data_->worldview_property) || - utils::startswith(property_key, baton_data_->hidden_prefix + baton_data_->worldview_property)) + (property_key == baton_data_->worldview_property) || + (property_key == baton_data_->hidden_prefix + baton_data_->worldview_property)) { // skip feature only if the value of incompatible worldview key is not 'all' if (property_key == incompatible_worldview_key) @@ -799,8 +799,8 @@ struct LocalizeWorker : Napi::AsyncWorker } else if ( - utils::startswith(property_key, baton_data_->class_property) || - utils::startswith(property_key, baton_data_->hidden_prefix + baton_data_->class_property)) + (property_key == baton_data_->class_property) || + (property_key == baton_data_->hidden_prefix + baton_data_->class_property)) { // check if the property is of higher precedence that class key encountered so far std::uint32_t idx = static_cast(std::distance(class_key_precedence.begin(), std::find(class_key_precedence.begin(), class_key_precedence.end(), property_key))); diff --git a/test/vtcomposite-localize-class.test.js b/test/vtcomposite-localize-class.test.js index 67b1802..1f4e835 100644 --- a/test/vtcomposite-localize-class.test.js +++ b/test/vtcomposite-localize-class.test.js @@ -239,16 +239,18 @@ test('[localize class] requesting localized worldview; feature with compatible w id: 10, tags: [ 0, 0, // _mbx_worldview - 1, 1 // _mbx_class + 1, 1, // _mbx_class + 2, 2 ], type: 1, // point geometry: [9, 55, 38] } ], - keys: ['_mbx_worldview', '_mbx_class'], + keys: ['_mbx_worldview', '_mbx_class', 'classes'], values: [ { string_value: 'US' }, { string_value: 'affogato' }, + { string_value: 'should_not_change' }, ], extent: 4096 } @@ -265,7 +267,7 @@ test('[localize class] requesting localized worldview; feature with compatible w const tile = vtinfo(vtBuffer); assert.ok('admin' in tile.layers, 'has admin layer'); assert.equal(tile.layers.admin.length, 1, 'has one feature'); - assert.deepEqual(tile.layers.admin.feature(0).properties, { worldview: 'US', class: 'affogato' }, 'expected properties'); + assert.deepEqual(tile.layers.admin.feature(0).properties, { worldview: 'US', class: 'affogato', classes: 'should_not_change' }, 'expected properties'); assert.end(); }); });