Passing an invalid columns_array hash key to the quotes method causes incorrect results in the values for the following keys. The final n key values are nil based on n invalid keys supplied.
Note that the doesnotexist key is present in the result and the value for shares_outstanding has moved to the doesnotexist key. The value for the final key last_trade_price is nil.
Patch
The following is a possible patch which returns nil from the quotes method in the event an invalid key is supplied. A better approach would be to drop the invalid key from columns_array before performing the query, or possibly raise an error instead.
diff --git a/lib/yahoo-finance.rb b/lib/yahoo-finance.rb
index ef924da..3e6c4f6 100755
--- a/lib/yahoo-finance.rb
+++ b/lib/yahoo-finance.rb
@@ -115,6 +115,13 @@ module YahooFinance
:symbol, :last_trade_price, :last_trade_date,
:change, :previous_close], options = {})
+ columns_array.each do |c|
+ unless COLUMNS.key?(c)
+ # TODO: raise an error
+ return nil
+ end
+ end
+
options[:raw] ||= true
ret = []
symbols_array.each_slice(SYMBOLS_PER_REQUEST) do |symbols|
Edit: In hindsight it might be easier just to drop the keys. I've submitted PR #36 for this.
Passing an invalid
columns_array
hash key to thequotes
method causes incorrect results in the values for the following keys. The final n key values arenil
based on n invalid keys supplied.Example - Valid keys
Result:
Example - Invalid key
doesnotexist
:Result:
Note that the
doesnotexist
key is present in the result and the value forshares_outstanding
has moved to thedoesnotexist
key. The value for the final keylast_trade_price
isnil
.Patch
The following is a possible patch which returns
nil
from thequotes
method in the event an invalid key is supplied. A better approach would be to drop the invalid key fromcolumns_array
before performing the query, or possibly raise an error instead.Edit: In hindsight it might be easier just to drop the keys. I've submitted PR #36 for this.