Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
U
uritemplate-js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
uritemplate-js
Commits
1663b469
Commit
1663b469
authored
Jan 20, 2013
by
fxa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed bug with {?empty}
parent
ead0b6f0
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
64 additions
and
19 deletions
+64
-19
README.md
README.md
+1
-0
bin/uritemplate-min.js
bin/uritemplate-min.js
+1
-1
bin/uritemplate.js
bin/uritemplate.js
+23
-7
src/VariableExpression.js
src/VariableExpression.js
+22
-6
test/integration/testRfcSamples.js
test/integration/testRfcSamples.js
+6
-0
test/unit/testVariableExpression.js
test/unit/testVariableExpression.js
+11
-5
No files found.
README.md
View file @
1663b469
...
...
@@ -60,6 +60,7 @@ MIT License, see http://mit-license.org/
Release Notes
-------------
*
0.2.3 fixed bug with empty objects ('{?empty}' with '{empty:{}}' shall expand to '?empty=')
*
0.2.2 fixed pct encoding bug with multibyte utf8 chars
*
0.2.1 fixed a bug in package.json
*
0.2.0 heavy project refactoring, splitting source files, introducing jshint (preparation of next steps)
...
...
bin/uritemplate-min.js
View file @
1663b469
This diff is collapsed.
Click to expand it.
bin/uritemplate.js
View file @
1663b469
...
...
@@ -584,22 +584,22 @@ var VariableExpression = (function () {
varspec
=
this
.
varspecs
[
index
];
value
=
variables
[
varspec
.
varname
];
if
(
!
isDefined
(
value
))
{
continue
;
continue
;
}
if
(
isFirstVarspec
)
{
result
+=
this
.
operator
.
first
;
result
+=
operator
.
first
;
isFirstVarspec
=
false
;
}
else
{
result
+=
this
.
operator
.
separator
;
result
+=
operator
.
separator
;
}
valueIsArr
=
objectHelper
.
isArray
(
value
);
if
(
typeof
value
===
"
string
"
||
typeof
value
===
"
number
"
||
typeof
value
===
"
boolean
"
)
{
value
=
value
.
toString
();
if
(
this
.
operator
.
named
)
{
if
(
operator
.
named
)
{
result
+=
LiteralExpression
.
encodeLiteral
(
varspec
.
varname
);
if
(
value
===
''
)
{
result
+=
this
.
operator
.
ifEmpty
;
result
+=
operator
.
ifEmpty
;
continue
;
}
result
+=
'
=
'
;
...
...
@@ -607,7 +607,7 @@ var VariableExpression = (function () {
if
(
varspec
.
maxLength
&&
value
.
length
>
varspec
.
maxLength
)
{
value
=
value
.
substr
(
0
,
varspec
.
maxLength
);
}
result
+=
this
.
operator
.
encode
(
value
);
result
+=
operator
.
encode
(
value
);
}
else
if
(
varspec
.
maxLength
)
{
// 2.4.1 of the spec says: "Prefix modifiers are not applicable to variables that have composite values."
...
...
@@ -617,7 +617,7 @@ var VariableExpression = (function () {
if
(
operator
.
named
)
{
result
+=
LiteralExpression
.
encodeLiteral
(
varspec
.
varname
);
if
(
!
isDefined
(
value
))
{
result
+=
this
.
operator
.
ifEmpty
;
result
+=
operator
.
ifEmpty
;
continue
;
}
result
+=
'
=
'
;
...
...
@@ -629,6 +629,22 @@ var VariableExpression = (function () {
result
+=
objectHelper
.
reduce
(
value
,
operator
.
named
?
reduceNamedExploded
:
reduceUnnamedExploded
,
''
);
}
}
if
(
isFirstVarspec
)
{
// so no varspecs produced output.
var
oneExploded
=
false
;
for
(
index
=
0
;
index
<
this
.
varspecs
.
length
;
index
+=
1
)
{
if
(
this
.
varspecs
[
index
].
exploded
)
{
oneExploded
=
true
;
break
;
}
}
if
(
operator
.
named
&&
!
oneExploded
)
{
result
+=
operator
.
symbol
;
result
+=
varspec
.
varname
+
operator
.
ifEmpty
;
}
}
return
result
;
};
...
...
src/VariableExpression.js
View file @
1663b469
...
...
@@ -74,19 +74,19 @@ var VariableExpression = (function () {
continue
;
}
if
(
isFirstVarspec
)
{
result
+=
this
.
operator
.
first
;
result
+=
operator
.
first
;
isFirstVarspec
=
false
;
}
else
{
result
+=
this
.
operator
.
separator
;
result
+=
operator
.
separator
;
}
valueIsArr
=
objectHelper
.
isArray
(
value
);
if
(
typeof
value
===
"
string
"
||
typeof
value
===
"
number
"
||
typeof
value
===
"
boolean
"
)
{
value
=
value
.
toString
();
if
(
this
.
operator
.
named
)
{
if
(
operator
.
named
)
{
result
+=
LiteralExpression
.
encodeLiteral
(
varspec
.
varname
);
if
(
value
===
''
)
{
result
+=
this
.
operator
.
ifEmpty
;
result
+=
operator
.
ifEmpty
;
continue
;
}
result
+=
'
=
'
;
...
...
@@ -94,7 +94,7 @@ var VariableExpression = (function () {
if
(
varspec
.
maxLength
&&
value
.
length
>
varspec
.
maxLength
)
{
value
=
value
.
substr
(
0
,
varspec
.
maxLength
);
}
result
+=
this
.
operator
.
encode
(
value
);
result
+=
operator
.
encode
(
value
);
}
else
if
(
varspec
.
maxLength
)
{
// 2.4.1 of the spec says: "Prefix modifiers are not applicable to variables that have composite values."
...
...
@@ -104,7 +104,7 @@ var VariableExpression = (function () {
if
(
operator
.
named
)
{
result
+=
LiteralExpression
.
encodeLiteral
(
varspec
.
varname
);
if
(
!
isDefined
(
value
))
{
result
+=
this
.
operator
.
ifEmpty
;
result
+=
operator
.
ifEmpty
;
continue
;
}
result
+=
'
=
'
;
...
...
@@ -116,6 +116,22 @@ var VariableExpression = (function () {
result
+=
objectHelper
.
reduce
(
value
,
operator
.
named
?
reduceNamedExploded
:
reduceUnnamedExploded
,
''
);
}
}
if
(
isFirstVarspec
)
{
// so no varspecs produced output.
var
oneExploded
=
false
;
for
(
index
=
0
;
index
<
this
.
varspecs
.
length
;
index
+=
1
)
{
if
(
this
.
varspecs
[
index
].
exploded
)
{
oneExploded
=
true
;
break
;
}
}
if
(
operator
.
named
&&
!
oneExploded
)
{
result
+=
operator
.
symbol
;
result
+=
varspec
.
varname
+
operator
.
ifEmpty
;
}
}
return
result
;
};
...
...
test/integration/testRfcSamples.js
View file @
1663b469
...
...
@@ -58,6 +58,12 @@ module.exports = (function () {
test
.
fail
(
'
chapter
'
+
chapterName
+
'
, template
'
+
template
+
'
threw error:
'
+
JSON
.
stringify
(
exception
,
null
,
4
));
return
;
}
if
(
expected
.
constructor
===
Array
)
{
// simplyfy arrays, when only one element is in
if
(
expected
.
length
===
1
)
{
expected
=
expected
[
0
];
}
}
if
(
expected
.
constructor
===
Array
)
{
// actual must match at least one of the listed elements
for
(
index
=
0
;
index
<
expected
.
length
;
index
+=
1
)
{
...
...
test/unit/testVariableExpression.js
View file @
1663b469
...
...
@@ -25,16 +25,22 @@ module.exports = (function () {
test
.
equal
(
ve
.
expand
({
x
:
1
,
y
:
2
}),
'
1,2
'
);
test
.
equal
(
ve
.
expand
({
x
:
1
,
y
:
null
}),
'
1
'
);
test
.
done
();
}
/* TODO this test fails
"exploded empty lists with ? must show the name": function (test) {
},
"
empty lists with ? must show the name
"
:
function
(
test
)
{
console
.
log
(
JSON
.
stringify
(
test
,
null
,
4
));
var
ve
=
new
VariableExpression
(
"
{?empty}
"
,
operators
.
valueOf
(
'
?
'
),
[
{
varname
:
'
empty
'
,
exploded
:
false
,
maxLength
:
null
}
]);
test
.
equal
(
ve
.
expand
({
empty
:
{}}),
'
?empty=
'
);
test
.
done
();
},
"
exploded empty lists with ? must not show the name
"
:
function
(
test
)
{
console
.
log
(
JSON
.
stringify
(
test
,
null
,
4
));
var
ve
=
new
VariableExpression
(
"
{?empty*}
"
,
operators
.
valueOf
(
'
?
'
),
[
{
varname
:
'
empty
'
,
exploded
:
true
,
maxLength
:
null
}
]);
test.equal(ve.expand({empty: {}}), '
?empty=
');
test
.
equal
(
ve
.
expand
({
empty
:
{}}),
''
);
test
.
done
();
}
*/
};
}());
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment