Skip to content

Commit 2e3dc51

Browse files
authored
fix identify parser
1 parent eb51d2f commit 2e3dc51

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

imagemagick.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@ function parseIdentify(input) {
103103
prop = {},
104104
props = [prop],
105105
prevIndent = 0,
106+
ident = 0,
106107
indents = [indent],
107-
currentLine, comps, indent, i, svg, svgText;
108+
currentLine, comps, svg, svgText;
108109
lines.shift(); //drop first line (Image: name.jpg)
109110
for (i in lines) {
110111
currentLine = lines[i];
@@ -118,29 +119,31 @@ function parseIdentify(input) {
118119
if (svg) {
119120
svgText += currentLine;
120121
} else {
121-
if (indent >= 0) {
122+
if (currentLine.length > 0) {
122123
comps = currentLine.split(': ');
123-
if (indent > prevIndent) indents.push(indent);
124-
while (indent < prevIndent && props.length) {
124+
indent = currentLine.search(/\S/);
125+
while (indent <= prevIndent) {
125126
indents.pop();
126127
prop = props.pop();
127128
prevIndent = indents[indents.length - 1];
128129
}
130+
129131
if (comps.length < 2) {
132+
indents.push(indent);
130133
props.push(prop);
131134
prop = prop[currentLine.split(':')[0].trim().toLowerCase()] = {};
135+
prevIndent = indent;
132136
} else {
133137
prop[comps[0].trim().toLowerCase()] = comps[1].trim()
134138
}
135-
prevIndent = indent;
136139
}
137140
}
138141
if (currentLine.match(/<\/svg>/)) {
139142
svg = false;
140143
prop['svg'] = svgText;
141144
}
142145
}
143-
return prop;
146+
return props[0];
144147
}
145148

146149
exports.identify = function(pathOrArgs, callback) {

0 commit comments

Comments
 (0)