Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bootstrap
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
bootstrap
Commits
83a7a698
Commit
83a7a698
authored
Mar 19, 2012
by
Jacob Thornton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
typeahead should escape regexp special chars
parent
bf59220b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
1 deletion
+18
-1
js/bootstrap-typeahead.js
js/bootstrap-typeahead.js
+2
-1
js/tests/unit/bootstrap-typeahead.js
js/tests/unit/bootstrap-typeahead.js
+16
-0
No files found.
js/bootstrap-typeahead.js
View file @
83a7a698
...
@@ -109,7 +109,8 @@
...
@@ -109,7 +109,8 @@
}
}
,
highlighter
:
function
(
item
)
{
,
highlighter
:
function
(
item
)
{
return
item
.
replace
(
new
RegExp
(
'
(
'
+
this
.
query
+
'
)
'
,
'
ig
'
),
function
(
$1
,
match
)
{
var
query
=
this
.
query
.
replace
(
/
[
-[
\]
{}()*+?.,
\\
^$|#
\s]
/g
,
'
\\
$&
'
)
return
item
.
replace
(
new
RegExp
(
'
(
'
+
query
+
'
)
'
,
'
ig
'
),
function
(
$1
,
match
)
{
return
'
<strong>
'
+
match
+
'
</strong>
'
return
'
<strong>
'
+
match
+
'
</strong>
'
})
})
}
}
...
...
js/tests/unit/bootstrap-typeahead.js
View file @
83a7a698
...
@@ -52,6 +52,22 @@ $(function () {
...
@@ -52,6 +52,22 @@ $(function () {
typeahead
.
$menu
.
remove
()
typeahead
.
$menu
.
remove
()
})
})
test
(
"
should not explode when regex chars are entered
"
,
function
()
{
var
$input
=
$
(
'
<input />
'
).
typeahead
({
source
:
[
'
aa
'
,
'
ab
'
,
'
ac
'
,
'
mdo*
'
,
'
fat+
'
]
})
,
typeahead
=
$input
.
data
(
'
typeahead
'
)
$input
.
val
(
'
+
'
)
typeahead
.
lookup
()
ok
(
typeahead
.
$menu
.
is
(
"
:visible
"
),
'
typeahead is visible
'
)
equals
(
typeahead
.
$menu
.
find
(
'
li
'
).
length
,
1
,
'
has 1 item in menu
'
)
equals
(
typeahead
.
$menu
.
find
(
'
.active
'
).
length
,
1
,
'
one item is active
'
)
typeahead
.
$menu
.
remove
()
})
test
(
"
should hide menu when query entered
"
,
function
()
{
test
(
"
should hide menu when query entered
"
,
function
()
{
stop
()
stop
()
var
$input
=
$
(
'
<input />
'
).
typeahead
({
var
$input
=
$
(
'
<input />
'
).
typeahead
({
...
...
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