Comments (4)
Just ran in to this myself. I'm using unflatten to turn S3 keys in to a tree (by using '/' as a delimiter) and my S3 bucket has keys like 03/09/2014/filename.zip
which turns in to { 3: { 9: { 2014: 'filename.zip' } } }
I fixed this by checking opts.object
in the getKey
function and not casting to Number if it's set:
function getkey(key) {
var parsedKey = Number(key)
return (
opts.object ||
isNaN(parsedKey) ||
key.indexOf('.') !== -1
) ? key
: parsedKey
}
I realize that yes, you can pass {object:true} to unflatten, and it will not automatically assume it's an array, but then you get the opposite behavior. i.e. "Arrays turn into objects".
Does this actually happen though? It looks like unflatten handles this by returning non-Objects immediately:
if (Object.prototype.toString.call(target) !== '[object Object]') {
return target
}
I'll write some tests to make sure and submit a PR :)
from flat.
bump
from flat.
Any thoughts on resolving this? Same issue as described in the original issue being experienced over here.
from flat.
We're moving off this library because of this issue.
One possible fix: use a different delimiter for arrays.
flatten({ test: ['a', 'b', 'c'] });
could yield
{ 'test[0]': 'a', 'test[1]': 'b', 'test[2]': 'c' }
from flat.
Related Issues (20)
- unflatten object with number as key replaces object with an array of n number length HOT 1
- Prototype Pollution HOT 1
- Add transformFirst option to allow modification of key to provide first key capability HOT 1
- There is no 4.1.1 on npm HOT 8
- Should provide ES5 syntax build. HOT 1
- Deep Nested Objects HOT 2
- What option to make difference between object & array HOT 1
- Possible to keep parent key HOT 3
- High severity vulnerability detected HOT 3
- Why cats are also flattened? 🐈 HOT 1
- Deno support HOT 2
- maxDepth unflatten
- High security vulnerability in 4.1.1 HOT 1
- Unflatten method doesn't work with "toString" key
- Unflatten partial arrays
- Need a maintainer? HOT 6
- Rename `master` branch to `main`
- [question] how could we define don't flat some specific object by the key?
- Release version 6 HOT 25
- Feature request: add ability to prevent modifying certain value in `unflatten` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flat.