Skip to content

Commit b1b1e56

Browse files
committed
Merge branch 'hotfix/1.11.17'
2 parents 83f8353 + f613973 commit b1b1e56

File tree

3 files changed

+46
-12
lines changed

3 files changed

+46
-12
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.11.16
1+
1.11.17

src/metkit/mars/TypeParam.cc

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ class Rule : public metkit::mars::MarsExpandContext {
121121

122122
Rule::Rule(const Rule& other, const eckit::Value& matchers, const eckit::Value& values, const eckit::Value& ids) {
123123

124+
std::map<std::string, size_t> precedence;
125+
124126
const eckit::Value& keys = matchers.keys();
125127
for (size_t i = 0; i < keys.size(); ++i) {
126128
std::string name = keys[i];
@@ -132,7 +134,6 @@ Rule::Rule(const Rule& other, const eckit::Value& matchers, const eckit::Value&
132134
for (const std::string& v : other.values_) {
133135
values_.push_back(v);
134136
}
135-
136137
auto it = mapping_.begin();
137138
for (auto m : other.mapping_) {
138139
mapping_.emplace_hint(it, m.first, m.second);
@@ -159,16 +160,37 @@ Rule::Rule(const Rule& other, const eckit::Value& matchers, const eckit::Value&
159160
std::string v = aliases[j];
160161

161162
if (mapping_.find(v) != mapping_.end()) {
163+
auto it = precedence.find(v);
164+
165+
if (it != precedence.end() and (*it).second <= j) {
162166

163-
LOG_DEBUG_LIB(LibMetkit) << "Redefinition of param "
164-
<< v
165-
<< "='"
166-
<< first
167-
<< "', overriding previous value of '"
168-
<< mapping_[v]
169-
<< "' "
170-
<< *this
171-
<< std::endl;
167+
LOG_DEBUG_LIB(LibMetkit) << "Redefinition ignored: param "
168+
<< v
169+
<< "='"
170+
<< first
171+
<< "', keeping previous value of '"
172+
<< mapping_[v]
173+
<< "' "
174+
<< *this
175+
<< std::endl;
176+
continue;
177+
}
178+
else {
179+
180+
LOG_DEBUG_LIB(LibMetkit) << "Redefinition of param "
181+
<< v
182+
<< "='"
183+
<< first
184+
<< "', overriding previous value of '"
185+
<< mapping_[v]
186+
<< "' "
187+
<< *this
188+
<< std::endl;
189+
190+
precedence[v] = j;
191+
}
192+
} else {
193+
precedence[v] = j;
172194
}
173195

174196
mapping_[v] = first;
@@ -453,7 +475,6 @@ static void init() {
453475
}
454476

455477
(*rules).push_back(Rule{eckit::Value::makeMap(), ids.keys(), ids});
456-
// (*rules).push_back(Rule{eckit::Value::makeMap(), unambiguousIDs, ids});
457478
}
458479

459480
namespace metkit {

tests/test_expand.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,19 @@ CASE( "test_metkit_expand_param" ) {
364364

365365
EXPECT_EQUAL(params[0], "130");
366366
}
367+
{
368+
const char* text = "retrieve,class=od,date=20240723,domain=g,expver=0079,levtype=sfc,param=asn/cp/lsp/sf/tcc/tp,step=0,stream=oper,time=0000,type=fc";
369+
MarsRequest r = MarsRequest::parse(text);
370+
auto params = r.values("param");
371+
EXPECT_EQUAL(params.size(), 6);
372+
373+
EXPECT_EQUAL(params[0], "32");
374+
EXPECT_EQUAL(params[1], "143");
375+
EXPECT_EQUAL(params[2], "142");
376+
EXPECT_EQUAL(params[3], "144");
377+
EXPECT_EQUAL(params[4], "164");
378+
EXPECT_EQUAL(params[5], "228");
379+
}
367380
}
368381

369382
//-----------------------------------------------------------------------------

0 commit comments

Comments
 (0)