gemini-code-assist[bot] commented on code in PR #38949:
URL: https://github.com/apache/beam/pull/38949#discussion_r3404968613
##########
website/www/site/assets/js/bootstrap.js:
##########
@@ -502,7 +502,8 @@ if (typeof jQuery === 'undefined') {
var clickHandler = function (e) {
var href
var $this = $(this)
- var $target = $($this.attr('data-target') || (href = $this.attr('href'))
&& href.replace(/.*(?=#[^\s]+$)/, '')) // strip for ie7
+ var selector = $this.attr('data-target') || (href = $this.attr('href')) &&
href.replace(/.*(?=#[^\s]+$)/, '') // strip for ie7
+ var $target = $(document).find(selector)
Review Comment:

If `selector` is empty or undefined, calling `$(document).find(selector)`
will throw a syntax error. Adding a guard to check if `selector` is truthy
before querying ensures that the click handler does not crash when the target
is missing.
```suggestion
var selector = $this.attr('data-target') || (href = $this.attr('href'))
&& href.replace(/.*(?=#[^\s]+$)/, '') // strip for ie7
var $target = selector ? $(document).find(selector) : $()
```
##########
website/www/site/assets/js/bootstrap.js:
##########
@@ -109,7 +109,7 @@ if (typeof jQuery === 'undefined') {
selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') // strip
for ie7
}
- var $parent = $(selector)
+ var $parent = $(document).find(selector)
Review Comment:

If `selector` is empty, undefined, or null, passing it directly to
`$(document).find()` will throw a jQuery syntax error. To prevent runtime
exceptions and preserve the original behavior where an empty selector safely
returned an empty jQuery collection, we should add a guard to ensure `selector`
is truthy before querying.
```suggestion
var $parent = selector ? $(document).find(selector) : $()
```
##########
website/www/site/assets/js/bootstrap.js:
##########
@@ -691,7 +692,7 @@ if (typeof jQuery === 'undefined') {
var target = $trigger.attr('data-target')
|| (href = $trigger.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')
// strip for ie7
- return $(target)
+ return $(document).find(target)
Review Comment:

If `target` is empty or undefined, `$(document).find(target)` will throw a
syntax error. Guarding the query with a truthy check ensures robust behavior.
```suggestion
return target ? $(document).find(target) : $()
```
##########
website/www/site/assets/js/bootstrap.js:
##########
@@ -1230,7 +1231,8 @@ if (typeof jQuery === 'undefined') {
$(document).on('click.bs.modal.data-api', '[data-toggle="modal"]', function
(e) {
var $this = $(this)
var href = $this.attr('href')
- var $target = $($this.attr('data-target') || (href &&
href.replace(/.*(?=#[^\s]+$)/, ''))) // strip for ie7
+ var selector = $this.attr('data-target') || (href &&
href.replace(/.*(?=#[^\s]+$)/, '')) // strip for ie7
+ var $target = $(document).find(selector)
Review Comment:

If `selector` is empty or undefined, calling `$(document).find(selector)`
will throw a syntax error. Adding a guard to check if `selector` is truthy
before querying ensures that the click handler does not crash when the target
is missing.
```suggestion
var selector = $this.attr('data-target') || (href &&
href.replace(/.*(?=#[^\s]+$)/, '')) // strip for ie7
var $target = selector ? $(document).find(selector) : $()
```
##########
website/www/site/assets/js/bootstrap.js:
##########
@@ -1550,11 +1552,18 @@ if (typeof jQuery === 'undefined') {
.css(isVertical ? 'top' : 'left', '')
}
+ function sanitizeHtml(string) {
+ if (typeof DOMPurify !== 'undefined') {
+ return DOMPurify.sanitize(string)
+ }
+ return string
+ }
Review Comment:

If `string` is not of type `'string'` (e.g., `undefined`, `null`, or an
object), passing it directly to `DOMPurify.sanitize` might cause unexpected
behavior, such as returning the string `"undefined"` or throwing a TypeError
depending on the DOMPurify version. Adding a type check ensures we only
sanitize actual string values.
```suggestion
function sanitizeHtml(string) {
if (typeof DOMPurify !== 'undefined' && typeof string === 'string') {
return DOMPurify.sanitize(string)
}
return string
}
```
##########
website/www/site/assets/js/bootstrap/alert.js:
##########
@@ -31,7 +31,7 @@
selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') // strip
for ie7
}
- var $parent = $(selector)
+ var $parent = $(document).find(selector)
Review Comment:

If `selector` is empty, undefined, or null, passing it directly to
`$(document).find()` will throw a jQuery syntax error. To prevent runtime
exceptions and preserve the original behavior where an empty selector safely
returned an empty jQuery collection, we should add a guard to ensure `selector`
is truthy before querying.
```suggestion
var $parent = selector ? $(document).find(selector) : $()
```
##########
website/www/site/assets/js/bootstrap/modal.js:
##########
@@ -320,7 +320,8 @@
$(document).on('click.bs.modal.data-api', '[data-toggle="modal"]', function
(e) {
var $this = $(this)
var href = $this.attr('href')
- var $target = $($this.attr('data-target') || (href &&
href.replace(/.*(?=#[^\s]+$)/, ''))) // strip for ie7
+ var selector = $this.attr('data-target') || (href &&
href.replace(/.*(?=#[^\s]+$)/, '')) // strip for ie7
+ var $target = $(document).find(selector)
Review Comment:

If `selector` is empty or undefined, calling `$(document).find(selector)`
will throw a syntax error. Adding a guard to check if `selector` is truthy
before querying ensures that the click handler does not crash when the target
is missing.
```suggestion
var selector = $this.attr('data-target') || (href &&
href.replace(/.*(?=#[^\s]+$)/, '')) // strip for ie7
var $target = selector ? $(document).find(selector) : $()
```
##########
website/www/site/assets/js/bootstrap/tooltip.js:
##########
@@ -302,11 +302,18 @@
.css(isVertical ? 'top' : 'left', '')
}
+ function sanitizeHtml(string) {
+ if (typeof DOMPurify !== 'undefined') {
+ return DOMPurify.sanitize(string)
+ }
+ return string
+ }
Review Comment:

If `string` is not of type `'string'` (e.g., `undefined`, `null`, or an
object), passing it directly to `DOMPurify.sanitize` might cause unexpected
behavior, such as returning the string `"undefined"` or throwing a TypeError
depending on the DOMPurify version. Adding a type check ensures we only
sanitize actual string values.
```suggestion
function sanitizeHtml(string) {
if (typeof DOMPurify !== 'undefined' && typeof string === 'string') {
return DOMPurify.sanitize(string)
}
return string
}
```
##########
website/www/site/assets/js/bootstrap/collapse.js:
##########
@@ -159,7 +159,7 @@
var target = $trigger.attr('data-target')
|| (href = $trigger.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')
// strip for ie7
- return $(target)
+ return $(document).find(target)
Review Comment:

If `target` is empty or undefined, `$(document).find(target)` will throw a
syntax error. Guarding the query with a truthy check ensures robust behavior.
```suggestion
return target ? $(document).find(target) : $()
```
##########
website/www/site/assets/js/bootstrap/carousel.js:
##########
@@ -208,7 +208,8 @@
var clickHandler = function (e) {
var href
var $this = $(this)
- var $target = $($this.attr('data-target') || (href = $this.attr('href'))
&& href.replace(/.*(?=#[^\s]+$)/, '')) // strip for ie7
+ var selector = $this.attr('data-target') || (href = $this.attr('href')) &&
href.replace(/.*(?=#[^\s]+$)/, '') // strip for ie7
+ var $target = $(document).find(selector)
Review Comment:

If `selector` is empty or undefined, calling `$(document).find(selector)`
will throw a syntax error. Adding a guard to check if `selector` is truthy
before querying ensures that the click handler does not crash when the target
is missing.
```suggestion
var selector = $this.attr('data-target') || (href = $this.attr('href'))
&& href.replace(/.*(?=#[^\s]+$)/, '') // strip for ie7
var $target = selector ? $(document).find(selector) : $()
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]