Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modal plugin set _isTransitioning after the trigger of hide event #24318

Merged
merged 1 commit into from
Oct 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions js/src/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,6 @@ const Modal = (() => {
return
}

const transition = Util.supportsTransitionEnd() && $(this._element).hasClass(ClassName.FADE)

if (transition) {
this._isTransitioning = true
}

const hideEvent = $.Event(Event.HIDE)

$(this._element).trigger(hideEvent)
Expand All @@ -185,6 +179,12 @@ const Modal = (() => {

this._isShown = false

const transition = Util.supportsTransitionEnd() && $(this._element).hasClass(ClassName.FADE)

if (transition) {
this._isTransitioning = true
}

this._setEscapeEvent()
this._setResizeEvent()

Expand Down
22 changes: 22 additions & 0 deletions js/tests/visual/modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ <h4 class="modal-title" id="firefoxModalLabel">Firefox Bug Test</h4>
<button type="button" class="btn btn-secondary btn-lg" data-toggle="modal" data-target="&#x3C;div class=&#x22;modal fade the-bad&#x22; tabindex=&#x22;-1&#x22; role=&#x22;dialog&#x22;&#x3E;&#x3C;div class=&#x22;modal-dialog&#x22; role=&#x22;document&#x22;&#x3E;&#x3C;div class=&#x22;modal-content&#x22;&#x3E;&#x3C;div class=&#x22;modal-header&#x22;&#x3E;&#x3C;button type=&#x22;button&#x22; class=&#x22;close&#x22; data-dismiss=&#x22;modal&#x22; aria-label=&#x22;Close&#x22;&#x3E;&#x3C;span aria-hidden=&#x22;true&#x22;&#x3E;&#x26;times;&#x3C;/span&#x3E;&#x3C;/button&#x3E;&#x3C;h4 class=&#x22;modal-title&#x22;&#x3E;The Bad Modal&#x3C;/h4&#x3E;&#x3C;/div&#x3E;&#x3C;div class=&#x22;modal-body&#x22;&#x3E;This modal&#x27;s HTTML source code is declared inline, inside the data-target attribute of it&#x27;s show-button&#x3C;/div&#x3E;&#x3C;/div&#x3E;&#x3C;/div&#x3E;&#x3C;/div&#x3E;">
Modal with an XSS inside the data-target
</button>

<br><br>

<button type="button" class="btn btn-secondary btn-lg" id="btnPreventModal">
Launch prevented modal on hide (to see the result open your console)
</button>
</div>

<script src="../../../assets/js/vendor/jquery-slim.min.js"></script>
Expand Down Expand Up @@ -203,6 +209,22 @@ <h4 class="modal-title" id="firefoxModalLabel">Firefox Bug Test</h4>
$('#firefoxModal').on('focus', reportFirefoxTestResult.bind(false))
$('#ff-bug-input').on('focus', reportFirefoxTestResult.bind(true))
})

$('#btnPreventModal').on('click', function () {
$('#firefoxModal').one('shown.bs.modal', function () {
$(this).modal('hide')
})
.one('hide.bs.modal', function (event) {
event.preventDefault()
if ($(this).data('bs.modal')._isTransitioning) {
console.error('Modal plugin should not set _isTransitioning when hide event is prevented')
} else {
console.log('Test passed')
$(this).modal('hide') // work as expected
}
})
.modal('show')
})
})
</script>
</body>
Expand Down