Skip to content

Commit d021726

Browse files
tf: lowercase %fields% during tf_compile, unless they start with a ':', which gives free case-insensitive compare (fixes #3153)
1 parent 32c9bbb commit d021726

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

Tests/TitleFormattingTests.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2838,3 +2838,11 @@ TEST_F(TitleFormattingTests, test_putMetaData) {
28382838
tf_free (bc);
28392839
EXPECT_STREQ(buffer, "TheAlbumArtist");
28402840
}
2841+
2842+
TEST_F(TitleFormattingTests, test_upperCaseField) {
2843+
pl_add_meta (it, "track", "5");
2844+
char *bc = tf_compile("%TRACK NUMBER%");
2845+
tf_eval (&ctx, bc, buffer, sizeof(buffer));
2846+
tf_free (bc);
2847+
EXPECT_STREQ(buffer, "5");
2848+
}

src/tf.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3997,15 +3997,27 @@ tf_compile_field (tf_compiler_t *c) {
39973997

39983998
uint8_t *type_ptr = c->o++;
39993999

4000-
const char *fstart = c->i;
40014000
uint8_t *plen = c->o;
40024001
c->o += 1;
4002+
int index = 0;
4003+
int should_lowercase = 0;
4004+
const char *fstart = c->o;
40034005
while (*(c->i)) {
40044006
if (*(c->i) == '%') {
40054007
break;
40064008
}
40074009
else {
4008-
*(c->o++) = *(c->i++);
4010+
if (index == 0) {
4011+
if (*(c->i) != ':') {
4012+
should_lowercase = 1;
4013+
}
4014+
index++;
4015+
}
4016+
char chr = *(c->i++);
4017+
if (should_lowercase) {
4018+
chr = (char)tolower(chr);
4019+
}
4020+
*(c->o++) = chr;
40094021
}
40104022
}
40114023
if (*(c->i) != '%') {

0 commit comments

Comments
 (0)