Skip to content

Commit

Permalink
Use a regex to parse filter arguments
Browse files Browse the repository at this point in the history
This fixes the problem where the filter arguments were naively split on
whitespace.
  • Loading branch information
tbranyen committed Aug 27, 2015
1 parent 7f559ba commit 9091802
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ define(function(require, exports, module) {

var parseProperty = require("./utils/parse_property");

// This breaks up the filter arguments by space delimited or between quotes,
// preserves the whitespace inside strings.
var filtersRegex = /[ ]|(['"][^'"]*['"])/;

/**
* Represents a Tree.
*
Expand Down Expand Up @@ -373,18 +377,18 @@ define(function(require, exports, module) {
previous = node;
}

// Split up the input into space-delimited parts.
var parts = input.trim().split(" ");
// This regex breaks up either by whitespace or between string quotes.
var parts = input.trim().split(filtersRegex).filter(Boolean);

// The partial name.
// The filter name.
current.value = parts[0];

// If no value, this is an error.
if (!current.value) {
throw new Error("Missing valid filter name.");
}

// Partials have arguments passed.
// Filters have arguments passed.
current.args = parts.slice(1).map(parseProperty);

return root;
Expand Down

0 comments on commit 9091802

Please sign in to comment.