Skip to content

Commit

Permalink
Fix bug in regex for template name creation #208
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian-hiller committed May 29, 2024
1 parent 7acfada commit a35a8d5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/decode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ describe('decode', () => {
test('should decode numbers', () => {
const formData = new FormData();
formData.append('integer', '123');
formData.append('integer_2', '123');
formData.append('float', '0.123');
formData.append('signed', '-123');
expect(
decode(formData, { numbers: ['integer', 'float', 'signed'] })
decode(formData, {
numbers: ['integer', 'integer_2', 'float', 'signed'],
})
).toEqual({
integer: 123,
integer_2: 123,
float: 0.123,
signed: -123,
});
Expand Down
5 changes: 4 additions & 1 deletion src/decode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ export function decode<
// Add each form entry to values
for (const [path, input] of formData.entries()) {
// Create template name and keys
const templateName = path.replace(/.\d+./g, '.$.').replace(/.\d+$/, '.$');
const templateName = path
.replace(/\.\d+\./g, '.$.')
.replace(/\.\d+$/, '.$');
const templateKeys = templateName.split('.');

// Add value of current field to values
Expand Down Expand Up @@ -77,6 +79,7 @@ export function decode<
(input && (typeof input === 'string' || input.size))
) {
// Get field value
console.log('templateName', templateName);
let output = getFieldValue(info, templateName, input);

// Transform value if necessary
Expand Down

0 comments on commit a35a8d5

Please sign in to comment.