-
-
Notifications
You must be signed in to change notification settings - Fork 925
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
Base64.decode64 isn't working as MRI implementation #2815
Comments
I searched a little bit and found similar issue for MRI ruby/ruby#815. They merged support for padding in |
@Myuzu I have requested that the fix for ruby/ruby#815 be backported to 2.2, since we use mostly-unmodified MRI stdlib. |
9.1.9.0 behaves just like MRI 2.3.3 Base64.encode64 "some_string"
# => "c29tZV9zdHJpbmc=\n"
Base64.decode64 "c29tZV9zdHJpbmc"
# => "some_string"
Base64.urlsafe_decode64 "c29tZV9zdHJpbmc"
# => "some_string"
Base64.strict_decode64 "c29tZV9zdHJpbmc"
# => ArgumentError: invalid base64 |
@MSNexploder Thanks for checking! |
i can't upgrade my jruby from 1.3, any work around ? |
@alejandroMA you can just monkey patch from here: https://github.com/ruby/ruby/blob/4c4b5be013466f8fab88568442dcea177c4480e1/lib/base64.rb |
thank you @Myuzu , although I already tried that: cfdi = '<cfdi:Comprobante version="3.2" serie="Q" folio="2674" fecha="2017-11-08T13:03:34" sello="D63gob+YmFpXyJYJPbdKbJCKvUMoM6gEaB/euv2rkma0RH15yFV/PCoS18f4rxI9TKXky7qAmivFJKFTbZRuV3+YmVslLnqnM5opf8kFKH6PMzjPUGu+8xSN1ie+VUAq49ISWyl6TGbVKNcCoMwHMtttk++OV8EqTE3KnRfT7qBQ8wSYm++KC/BKawytGGeJQqVsSjjM7sQjT1ZM36EEW4DmEBo7QUvP12ntGcr3IbK9036dj7uFbcy5eWabIKEhyarWshXQiX2e9rLCsWHH4zlj4QqY6pSY7hiPcHsOd8v1lygTYiKlLovjse90ceguCf2Ar60hRNxCkAm5QsfpWA==" formaDePago="pago en una sola exhibicion" noCertificado="00001000000404442195" certificado="MIIGCTCCA/GgAwIBAgIUMDAwMDEwMDAwMDA0MDQ0NDIxOTUwDQYJKoZIh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6aTVEZgr7HIQNpYtejjT/j1EvPOWsy3qqt4usW4MHV7/U7+yFuk2UtWNgXioVAaNxVWA5Ag59Gkf9DKuxdoR1Y+GrnxZiVd1eZYfyZw12mr7XtN+0qY9gXTCppIWA/W2RSY/G8IqcvfGGFB9EspkpWnp8gZX08BEREr/iVtfj3NhjtSRDs220sXW5M9X1TSRx+vAgMBAAGjHTAbMAwGA1UdEwEB/wQCMAAwCwYDVR0PBAQDAgbAMA0GCSqGSIb3DQEBCwUAA4ICAQChbKD0+xHTDwh1sI/OOfW50dchY6q3c/PzscUELTDksc5kkxEHSfV/kDnMPSTfsh+L0ocYD8/B72RkqPiYgOE10Bnt+QjVu1/KR+RZdCJ3NCuL6/sC+Zr+ErIey7+iRPG//JaWDJ5QqmpVJ56mCdOPA2mU+duq7segNEc/8b1S7IzxbssUabYTZdmROx0H/vah22vd5F9xOi96vlWF/g6jGSg1X3xlzKMkIvXkEGt3LcB7q3R4r9gojEgFYu4nLtXDjndVJYlw+oTK7DgLP3amPV9Id6mstmCXUMnkgIOyo6waSyGFP9hkop6fcvuNkY6iQcnUHUspnJpaG3w2bIvh2HoddSdv5jU0G6elLUA3XSLQPxKRZAIYieTPDY6c0rD2Hh+rTwfIOorc7BfcbE94/4wGoq0AWw/2VWvQB2sxY0fvgG/RKE16xGLFcRqy94MUnCv+tKzfEWUiTRcWUAOG3LxHJAhEisw21ltdFqI03azm2S1o/dh0PlYX7Unw6NCFJMJebE1uXmL+XQoUSquCc4pXLE47Zjd7F49eIvMuPmYMcMlTou/Mv4R3Bw+NA4KCYoqCjP0Re8ptpMAWYjwBcDCHjL7xDtlJad92O0ey/LKAf1bwEn3/iCfe2zPO+9rH8VT0JnbBoxlgJ/uszUOmwZLtcj0zeQ0lZA+a8aG0og==" condicionesDePago="CREDITO" subTotal="1415700.00" descuento="0.00" motivoDescuento="X" TipoCambio="1.000" Moneda="Pesos" total="1642212.00" tipoDeComprobante="ingreso" metodoDePago="03" LugarExpedicion="El Marqués,QUERETARO" NumCtaPago="5491" xsi:schemaLocation="http://www.sat.gob.mx/cfd/3 http://www.sat.gob.mx/sitio_internet/cfd/3/cfdv32.xsd" xmlns:cfdi="http://www.sat.gob.mx/cfd/3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><cfdi:Emisor rfc="EMY861219J58" nombre="EMYCSA S.A. DE C.V."><cfdi:DomicilioFiscal calle="KM 207 MAS 700 CARRETERA A DELICIAS " noExterior="SN" colonia="Aquiles Serdán" localidad="CHIHUAHUA" municipio="Aquiles Serdán" estado="CHIHUAHUA" pais="MEXICO" codigoPostal="31650" /><cfdi:ExpedidoEn calle="EL TEPEYAC" noExterior="11090" colonia="El Tepeyac" municipio="El Marqués" estado="QUERETARO" pais="MEXICO" codigoPostal="76250" /><cfdi:RegimenFiscal Regimen="REGIMEN GENERAL DE PERSONAS MORALES" /></cfdi:Emisor><cfdi:Receptor rfc="CCU910805CP8" nombre="CONSTRUCTORA CHUFANI SA DE CV"><cfdi:Domicilio calle="CIRCUITO PALMA COCOTERA" noExterior="2020" colonia="PALMARES DE QUERETARO" localidad="QUERETARO" municipio="Querétaro" estado="QUERETARO" pais="MEXICO" codigoPostal="76127" /></cfdi:Receptor><cfdi:Conceptos><cfdi:Concepto cantidad="1" unidad="NO APLICA" descripcion="ESTIMACION NO. 5" valorUnitario="2178000.00" importe="2178000.00" /><cfdi:Concepto cantidad="1" unidad="NO APLICA" descripcion="25% AMORTIZACION DE ANTICIPO" valorUnitario="-544500.00" importe="-544500.00" /><cfdi:Concepto cantidad="1" unidad="NO APLICA" descripcion="10% FONDO DE GARANTIA
POR LOS TRABAJOS DE SUMINISTRO, FABRICACION Y MONTAJE
DE ESTRUCTURA Y CUBIERTA METALICA.
CONTRATO: 2017-1085-22324.
PROVEEDOR: 125.
PEDIDO: 4500022324.
ENTRADA: 1000114541.

DE LA OBRA: NHK SPRING MEXICO.
UBICADA EN: IRAPUATO, GTO." valorUnitario="-217800.00" importe="-217800.00" /></cfdi:Conceptos><cfdi:Impuestos totalImpuestosRetenidos="0.00" totalImpuestosTrasladados="226512"><cfdi:Retenciones><cfdi:Retencion impuesto="ISR" importe="0.00" /><cfdi:Retencion impuesto="IVA" importe="0.00" /></cfdi:Retenciones><cfdi:Traslados><cfdi:Traslado impuesto="IVA" tasa="16" importe="226512" /><cfdi:Traslado impuesto="IEPS" tasa="0" importe="0" /></cfdi:Traslados></cfdi:Impuestos><cfdi:Complemento><tfd:TimbreFiscalDigital version="1.0" UUID="f3f3a856-8a47-4fc6-bc89-a711c3688105" FechaTimbrado="2017-11-08T14:03:43" selloCFD="D63gob+YmFpXyJYJPbdKbJCKvUMoM6gEaB/euv2rkma0RH15yFV/PCoS18f4rxI9TKXky7qAmivFJKFTbZRuV3+YmVslLnqnM5opf8kFKH6PMzjPUGu+8xSN1ie+VUAq49ISWyl6TGbVKNcCoMwHMtttk++OV8EqTE3KnRfT7qBQ8wSYm++KC/BKawytGGeJQqVsSjjM7sQjT1ZM36EEW4DmEBo7QUvP12ntGcr3IbK9036dj7uFbcy5eWabIKEhyarWshXQiX2e9rLCsWHH4zlj4QqY6pSY7hiPcHsOd8v1lygTYiKlLovjse90ceguCf2Ar60hRNxCkAm5QsfpWA==" noCertificadoSAT="00001000000407908743" selloSAT="uAX5FqlUWnTqRBQm+j99NonxrL5YSzKE/obC3eDfhO1wUkiFlJootBWsdutyKdBibLNRjsdS4SqMNzH6ocMjAlB3Tdrlkma091f5xS7vESfVJMnh7Hcujq7nlwNmpFt6PZ6rWdYa5gJ6UEx55tF01N3p9VbYo5lJH0USIaqrb+fb2hB0Yzgm5/C9c//ios4TQMKw/qZcT87c0s6MYT4yIHN+NRo5g/4FbCGcjfYsD12il3makYjuGJxaXWU2onYnMIUvJ+JnhvQvR6sNs4Ifp1B7Y4oHsM5Ifxx0RCYkBRnAa6G97Iqv/aLQEOO0pQ4sIDjEESKT1ak6tTf9biiAQQ==" xsi:schemaLocation="http://www.sat.gob.mx/TimbreFiscalDigital http://www.sat.gob.mx/TimbreFiscalDigital/TimbreFiscalDigital.xsd" xmlns:tfd="http://www.sat.gob.mx/TimbreFiscalDigital" /></cfdi:Complemento></cfdi:Comprobante>'
encodedCfdi = [cfdi].pack("m0") it doesn’t generate the valid base64 string, it generates a close one, but not close enough do you have any other idea? |
@alejandroMA as I originally understand you need proper def urlsafe_encode64(bin, padding=true)
str = strict_encode64(bin).tr("+/", "-_")
str = str.delete("=") unless padding
str
end
def urlsafe_decode64(str)
str = str.tr("-_", "+/")
if !str.end_with?("=") && str.length % 4 != 0
str = str.ljust((str.length + 3) & ~3, "=")
end
strict_decode64(str)
end
encodedCfdi = urlsafe_encode64(cfdi, false) With this done you can safely ignore padding characters ( |
Sorry @Myuzu I think I misunderstood this "github issue", in jruby 1.3 "strict_encode64(bin)" is not even available, my problem is that "Base64.encode64(bin)" is yielding a wrong result, it breaks my original data. |
@alejandroMA can you provide actual and expected behavior on your data? |
yes @Myuzu Expected:
Result in jruby 1.3
original string
The start is very similar, but the ending is not. After further investigation the it seams the problem are iso-8859-1 careacters, there are some "é" on my string. |
@alejandroMA jruby, prior to version 1.7, is not known for decent encoding support :( Upgrading to 1.7 branch is not an option? |
@Myuzu mmm, i dont have more that 12h of experience in ruby, this work i'm doing as mantainance of a very old rails website. We'll try updataing to jruby on a virtual machine clone, and see what happens, but in the past when updating that website to another jruby it stoped working. What version of jruby do you recomend ? 1.7 ? does 1.7 have suport for "string.encode('utf-8')" ? Thank you so much for your help. |
@alejandroMA I'm actually not working with ruby anymore. As far as I recall, 1.7 branch do not have any issues with additional encodings support. Upgrading complex rails app could be real pain, done it couple times 😫 Wish you good luck with that! I suppose, guys here, can't help you because 1.3 branch is simply too old. All development effort is focused on JRuby 9000, and I doubt you can upgrade your app so far away. Nevertheless, if you will stuck upgrading the app, mail me and I try to help. |
I saw #2551 issue so some of these were fixed, but what about
Base64.decode64
? Should it returnsome_string
orsome_stri
if I remove padding from encoded string?The text was updated successfully, but these errors were encountered: