From aba0d22e47617a1112cb275d22010585b344cbf6 Mon Sep 17 00:00:00 2001 From: Audrey Tang Date: Sun, 11 Jan 2015 07:05:49 +0800 Subject: [PATCH] * Safeguard against $rb containing undefined elements. As seen in https://github.com/audreyt/moedict-webkit/issues/149 --- han.js | 2 ++ js/src/hyu/normalize.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/han.js b/han.js index 07a7784c..935764f9 100644 --- a/han.js +++ b/han.js @@ -1701,6 +1701,7 @@ function createNormalRu( $rb, $rt, attr ) { if ( Array.isArray( $rb )) { $ru.innerHTML = $rb.map(function( rb ) { + if (typeof rb == 'undefined') { return '' } return rb.outerHTML }).join('') } else { @@ -1988,6 +1989,7 @@ $.extend( Hyu, { rb = $ru.shift() aRb.push( rb ) } catch (e) {} + if (typeof rb == 'undefined') { break } span += Number( rb.getAttribute( 'span' ) || 1 ) } while ( rbspan > span ) diff --git a/js/src/hyu/normalize.js b/js/src/hyu/normalize.js index f4b6bdd6..0a829b62 100644 --- a/js/src/hyu/normalize.js +++ b/js/src/hyu/normalize.js @@ -16,6 +16,7 @@ function createNormalRu( $rb, $rt, attr ) { if ( Array.isArray( $rb )) { $ru.innerHTML = $rb.map(function( rb ) { + if (typeof rb == 'undefined') { return '' } return rb.outerHTML }).join('') } else { @@ -303,6 +304,7 @@ $.extend( Hyu, { rb = $ru.shift() aRb.push( rb ) } catch (e) {} + if (typeof rb == 'undefined') { break } span += Number( rb.getAttribute( 'span' ) || 1 ) } while ( rbspan > span )