Skip to content

Commit 24553f6

Browse files
committed
libutil/fluid: add FLUID_STRING_F58_PLAIN
Problem: in non-UX sitations it may be safer or required to encode FLUIDs using a prefix of f not ƒ, but there is no convenient way to do that. Add FLUID_STRING_F58_PLAIN encoding, which is the same as FLUID_STRING_F58, except that the prefix is forced to f. Update unit test.
1 parent 0ec34e0 commit 24553f6

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/common/libutil/fluid.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ static inline int is_utf8_locale (void)
189189
return 0;
190190
}
191191

192-
static int fluid_f58_encode (char *buf, int bufsz, fluid_t id)
192+
static int fluid_f58_encode (char *buf, int bufsz, fluid_t id, bool plain)
193193
{
194194
int count;
195195
const char *prefix = f58_prefix;
@@ -203,7 +203,7 @@ static int fluid_f58_encode (char *buf, int bufsz, fluid_t id)
203203

204204
#if !ASSUME_BROKEN_LOCALE
205205
/* Use alternate "f" prefix if locale is not multibyte */
206-
if (!is_utf8_locale())
206+
if (!is_utf8_locale() || plain)
207207
prefix = f58_alt_prefix;
208208
#endif
209209

@@ -332,7 +332,11 @@ int fluid_encode (char *buf, int bufsz, fluid_t fluid,
332332
return -1;
333333
break;
334334
case FLUID_STRING_F58:
335-
if (fluid_f58_encode (buf, bufsz, fluid) < 0)
335+
if (fluid_f58_encode (buf, bufsz, fluid, false) < 0)
336+
return -1;
337+
break;
338+
case FLUID_STRING_F58_PLAIN:
339+
if (fluid_f58_encode (buf, bufsz, fluid, true) < 0)
336340
return -1;
337341
break;
338342
case FLUID_STRING_EMOJI:

src/common/libutil/fluid.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ typedef enum {
2424
FLUID_STRING_MNEMONIC = 2, // mnemonicode x-x-x--x-x-x
2525
FLUID_STRING_F58 = 3, // FLUID base58 enc: ƒXXXX or fXXXX
2626
FLUID_STRING_EMOJI = 4, // FLUID basemoji enc: 😪🏭🐭🍑👨
27+
FLUID_STRING_F58_PLAIN = 5, // FLUID base58 enc: fXXXX
2728
} fluid_string_type_t;
2829

2930
struct fluid_generator {

src/common/libutil/test/fluid.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ void test_f58 (void)
103103
"fluid_encode with FLUX_F58_FORCE_ASCII used ascii prefix");
104104
if (unsetenv ("FLUX_F58_FORCE_ASCII") < 0)
105105
BAIL_OUT ("Failed to unsetenv FLUX_F58_FORCE_ASCII");
106+
107+
ok (fluid_encode (buf,
108+
sizeof (buf),
109+
f58_tests->id,
110+
FLUID_STRING_F58_PLAIN) == 0,
111+
"fluid_encode FLUX_STRING_F58_PLAIN works");
112+
is (buf, f58_tests->f58_alt,
113+
"fluid_encode FLUID_STRING_F58_PLAIN used ascii prefix");
106114
#endif
107115

108116
ok (fluid_encode (buf, 1, 1, type) < 0 && errno == EOVERFLOW,

0 commit comments

Comments
 (0)