简体   繁体   中英

Inconsistent wrapping of quotes in to_yaml

Introduction

In the below example, you can see that the header and sections 1 and 11 have been put in as plain values into the yaml, but sections 2 and 8 have been wrapped in single quotes. This seems to be happening at the to_yaml stage because in the hash everything looks ok. (I'm not simply loading a yaml and converting it back, this is just for the sake of a simplified example)

What I've tried

I've tried seeing if there are any special characters which would cause confusion, but without any luck. For example, on the word vehicle's there is a curled apostrophe rather than a straight one ' , but that is found in all sections. isn't in section 2 has the straight apostrophe. I tried adding/removing each type of apostrophe systematically in different sections to see if that would make any difference but it hasn't

foo.yml

en:
  contract:
    terms_and_conditions:
      FF:
        company: Foo Foo SA
        spain_checkin_company: Foo Foo Spain SLR
        title: Rental Agreement
        header: "This Rental Agreement regulates the rental conditions between Foo Foo, hereinafter referred to as the Rental
                Firm, and the client, identified by a valid driving license, hereinafter referred to as the Hirer, and it is ruled by all the
                general and special conditions described in this agreement, unless there is any written derogation or alteration."
        column_1:
          section_1:
            title: 1. Vehicle conditions
            text: "1) The customer acknowledges having received the Vehicle and rented extras in a clean condition and with all the features working. 2) The customer will return the vehicle in a clean condition, with the same amount of fuel at the pick-up, and with all the vehicle’s features operating in a normal way, on the return date, time and location established in the Rental Agreement. Failure to meet these criteria will result in additional charges to the Hirer according to the rental firm price table. Any loss or damage in rented extras, equipment or spare parts, will be fully charged to the Hirer according to the Rental Firm price table."
          section_2:
            title: 2. Documents
            text: "A valid vehicle driver’s license, ID or Passport and credit card (Visa or Mastercard) are required and must be presented upon the vehicle’s collection and signing of the rental agreement. If the Hirer does not bring the necessary documents, the vehicle cannot be rented and regular no show fee will apply. 2) To hold a valid license to drive in Europe is the responsibility of the Hirer 3) The Hirer should be older than 18 years old. 4) If the Hirer is under 25 years of age, purchasing the Standard Insurance plan is mandatory, and he/she isn't allowed to purchase the Basic or Full Insurance plan when renting a vehicle.
 5) The credit card owner must be present at the vehicle´s collection.
  "
        column_2:
          section_8:
            title: 8. Accident / Vehicle Damage
            text: "In the event of an accident or vehicle damage, the Hirer agrees to the following procedures: 1) Immediately notify the Rental Firm and police authorities of any accident, theft, robbery or other misfortune. 2) Take pictures and obtain names and addresses of all persons involved as well as witnesses, that can document what happened 3) Fill the accident report, together with other vehicles that may be involved. 4) Shall not leave the vehicle without taking all measures regarding its protection and . 5) Shall not take any responsibility or pled guilty, in the event of an accident that might hold the Rental Firm liable 6) Collect the accident report signed by all parties involved and the documents prepared by the police authorities, along with the vehicle keys, if retained (in case of vehicle theft) and send it immediately to the Rental firm. Otherwise, all insurances and coverage’s will expire, and the Hirer is liable for all expenses."
          section_11:
            title: 11. Liability / Security Deposit and After Rental Payments
            text: "1) The security deposit can only be paid by credit card (Visa or Mastercard), and the credit card owner must be present at the pick-up. At the vehicle delivery, the Hirer is required to pay the security deposit according to the chosen Insurance option. This amount will be held in the Hirer’s credit card to ensure the excess payment in the event of robbery or accident and any other vehicle damage during the rental period. 2) If the security deposit amount is not authorized by the bank or by the credit card owner, the contract cannot be executed and the vehicle cannot be delivered. In this case, the regular cancelation policy will apply and the full booking amount will be charged to the Hirer. The security deposit will be returned to the Hirer at the end of the rental period, after an inspection by a Rental Firm member staff, who shall state the vehicle is in similar conditions compared to when it was collected. 3) Vehicle damage and equipment/extras damage costs will be charged according to the Rental Firm price table. The Hirer will also be liable for the days not rented during the vehicle reasonable repair time, according to the damages at issue. 4) In case of an accident where the Hirer does not consider himself responsible, the Rental Firm will hold the full amount of the security deposit until the insurance company states the responsibility. 5) If the damage repair costs cannot be determined immediately, the Rental Firm will hold the full amount of the security deposit. A portion of the excess can be refunded in case the final damage repair costs are lower than the amount paid. 6) The Hirer agrees that the Rental Firm is authorized to charge the credit card on file for any further amounts that may arise such as wild camping, parking tickets, fines, traffic offence penalties, tolls, damages to the van (interior or exterior) and overdue amounts. Rental Firm is entitled to verify any of the damages to the van for 30 days after the last day of the rental agreement. In the event of a fine, the Rental Firm will always attempt to forward the fine to the Hirer. On these cases, a 25€ administrative fee will be charged by the Rental Firm. In the event that it is not possible to forward the fine to the Hirer, the Rental Firm will process the fine and charge to the Hirer the total cost of the fine plus VAT and an added administrative fee of 50€. 7) Hirer must provide the Rental Firm with an alternative credit card that can be used to meet Hirer’s obligations under the Rental Firm Terms and Conditions, in case of insufficient funds, declined transactions for any reason, and cancelled or suspended credit card. 8) All unpaid invoices will be added interest, which is the highest legal rate plus a flat fee, corresponding to 20% of the unpaid amount and any compensation for occurred damages / lost profits due by law. In the event of a legal dispute somehow related with this contract, the parties agree that the jurisdiction of the pick-up location will be applied."

hash in Ruby

foo = YAML.load(File.read("#{@PATH}foo.yml"))

=> {"en"=>
  {"contract"=>
    {"terms_and_conditions"=>
      {"FF"=>
        {"company"=>"Foo Foo SA",
         "spain_checkin_company"=>"Foo Foo Spain SLR",
         "title"=>"Rental Agreement",
         "header"=>
          "This Rental Agreement regulates the rental conditions between Foo Foo, hereinafter referred to as the Rental Firm, and the client, identified by a valid driving license, hereinafter referred to as the Hirer, and it is ruled by all the general and special conditions described in this agreement, unless there is any written derogation or alteration.",
         "column_1"=>
          {"section_1"=>
            {"title"=>"1. Vehicle conditions",
             "text"=>
              "1) The customer acknowledges having received the Vehicle and rented extras in a clean condition and with all the features working. 2) The customer will return the vehicle in a clean condition, with the same amount of fuel at the pick-up, and with all the vehicle’s features operating in a normal way, on the return date, time and location established in the Rental Agreement. Failure to meet these criteria will result in additional charges to the Hirer according to the rental firm price table. Any loss or damage in rented extras, equipment or spare parts, will be fully charged to the Hirer according to the Rental Firm price table."},
           "section_2"=>
            {"title"=>"2. Documents",
             "text"=>
              "A valid vehicle driver’s license, ID or Passport and credit card (Visa or Mastercard) are required and must be presented upon the vehicle’s collection and signing of the rental agreement. If the Hirer does not bring the necessary documents, the vehicle cannot be rented and regular no show fee will apply. 2) To hold a valid license to drive in Europe is the responsibility of the Hirer 3) The Hirer should be older than 18 years old. 4) If the Hirer is under 25 years of age, purchasing the Standard Insurance plan is mandatory, and he/she isn't allowed to purchase the Basic or Full Insurance plan when renting a vehicle. 5) The credit card owner must be present at the vehicle´s collection. "}},
         "column_2"=>
          {"section_8"=>
            {"title"=>"8. Accident / Vehicle Damage",
             "text"=>
              "In the event of an accident or vehicle damage, the Hirer agrees to the following procedures: 1) Immediately notify the Rental Firm and police authorities of any accident, theft, robbery or other misfortune. 2) Take pictures and obtain names and addresses of all persons involved as well as witnesses, that can document what happened 3) Fill the accident report, together with other vehicles that may be involved. 4) Shall not leave the vehicle without taking all measures regarding its protection and . 5) Shall not take any responsibility or pled guilty, in the event of an accident that might hold the Rental Firm liable 6) Collect the accident report signed by all parties involved and the documents prepared by the police authorities, along with the vehicle keys, if retained (in case of vehicle theft) and send it immediately to the Rental firm. Otherwise, all insurances and coverage’s will expire, and the Hirer is liable for all expenses."},
           "section_11"=>
            {"title"=>"11. Liability / Security Deposit and After Rental Payments",
             "text"=>
              "1) The security deposit can only be paid by credit card (Visa or Mastercard), and the credit card owner must be present at the pick-up. At the vehicle delivery, the Hirer is required to pay the security deposit according to the chosen Insurance option. This amount will be held in the Hirer’s credit card to ensure the excess payment in the event of robbery or accident and any other vehicle damage during the rental period. 2) If the security deposit amount is not authorized by the bank or by the credit card owner, the contract cannot be executed and the vehicle cannot be delivered. In this case, the regular cancelation policy will apply and the full booking amount will be charged to the Hirer. The security deposit will be returned to the Hirer at the end of the rental period, after an inspection by a Rental Firm member staff, who shall state the vehicle is in similar conditions compared to when it was collected. 3) Vehicle damage and equipment/extras damage costs will be charged according to the Rental Firm price table. The Hirer will also be liable for the days not rented during the vehicle reasonable repair time, according to the damages at issue. 4) In case of an accident where the Hirer does not consider himself responsible, the Rental Firm will hold the full amount of the security deposit until the insurance company states the responsibility. 5) If the damage repair costs cannot be determined immediately, the Rental Firm will hold the full amount of the security deposit. A portion of the excess can be refunded in case the final damage repair costs are lower than the amount paid. 6) The Hirer agrees that the Rental Firm is authorized to charge the credit card on file for any further amounts that may arise such as wild camping, parking tickets, fines, traffic offence penalties, tolls, damages to the van (interior or exterior) and overdue amounts. Rental Firm is entitled to verify any of the damages to the van for 30 days after the last day of the rental agreement. In the event of a fine, the Rental Firm will always attempt to forward the fine to the Hirer. On these cases, a 25€ administrative fee will be charged by the Rental Firm. In the event that it is not possible to forward the fine to the Hirer, the Rental Firm will process the fine and charge to the Hirer the total cost of the fine plus VAT and an added administrative fee of 50€. 7) Hirer must provide the Rental Firm with an alternative credit card that can be used to meet Hirer’s obligations under the Rental Firm Terms and Conditions, in case of insufficient funds, declined transactions for any reason, and cancelled or suspended credit card. 8) All unpaid invoices will be added interest, which is the highest legal rate plus a flat fee, corresponding to 20% of the unpaid amount and any compensation for occurred damages / lost profits due by law. In the event of a legal dispute somehow related with this contract, the parties agree that the jurisdiction of the pick-up location will be applied."}}}}}}}

Outputted yaml file

File.open("#{@PATH}foo.yml", "w") do |f|
              YAML.dump(foo,f)
            end

(also used f.puts foo.to_yaml ) with the same result

en:
  contract:
    terms_and_conditions:
      FF:
        company: Foo Foo SA
        spain_checkin_company: Foo Foo Spain SLR
        title: Rental Agreement
        header: This Rental Agreement regulates the rental conditions between Foo
          Foo, hereinafter referred to as the Rental Firm, and the client, identified
          by a valid driving license, hereinafter referred to as the Hirer, and it
          is ruled by all the general and special conditions described in this agreement,
          unless there is any written derogation or alteration.
        column_1:
          section_1:
            title: 1. Vehicle conditions
            text: 1) The customer acknowledges having received the Vehicle and rented
              extras in a clean condition and with all the features working. 2) The
              customer will return the vehicle in a clean condition, with the same
              amount of fuel at the pick-up, and with all the vehicle’s features operating
              in a normal way, on the return date, time and location established in
              the Rental Agreement. Failure to meet these criteria will result in
              additional charges to the Hirer according to the rental firm price table.
              Any loss or damage in rented extras, equipment or spare parts, will
              be fully charged to the Hirer according to the Rental Firm price table.
          section_2:
            title: 2. Documents
            text: 'A valid vehicle driver’s license, ID or Passport and credit card
              (Visa or Mastercard) are required and must be presented upon the vehicle’s
              collection and signing of the rental agreement. If the Hirer does not
              bring the necessary documents, the vehicle cannot be rented and regular
              no show fee will apply. 2) To hold a valid license to drive in Europe
              is the responsibility of the Hirer 3) The Hirer should be older than
              18 years old. 4) If the Hirer is under 25 years of age, purchasing the
              Standard Insurance plan is mandatory, and he/she isn''t allowed to purchase
              the Basic or Full Insurance plan when renting a vehicle. 5) The credit
              card owner must be present at the vehicle´s collection. '
        column_2:
          section_8:
            title: 8. Accident / Vehicle Damage
            text: 'In the event of an accident or vehicle damage, the Hirer agrees
              to the following procedures: 1) Immediately notify the Rental Firm and
              police authorities of any accident, theft, robbery or other misfortune.
              2) Take pictures and obtain names and addresses of all persons involved
              as well as witnesses, that can document what happened 3) Fill the accident
              report, together with other vehicles that may be involved. 4) Shall
              not leave the vehicle without taking all measures regarding its protection
              and . 5) Shall not take any responsibility or pled guilty, in the event
              of an accident that might hold the Rental Firm liable 6) Collect the
              accident report signed by all parties involved and the documents prepared
              by the police authorities, along with the vehicle keys, if retained
              (in case of vehicle theft) and send it immediately to the Rental firm.
              Otherwise, all insurances and coverage’s will expire, and the Hirer
              is liable for all expenses.'
          section_11:
            title: 11. Liability / Security Deposit and After Rental Payments
            text: 1) The security deposit can only be paid by credit card (Visa or
              Mastercard), and the credit card owner must be present at the pick-up.
              At the vehicle delivery, the Hirer is required to pay the security deposit
              according to the chosen Insurance option. This amount will be held in
              the Hirer’s credit card to ensure the excess payment in the event of
              robbery or accident and any other vehicle damage during the rental period.
              2) If the security deposit amount is not authorized by the bank or by
              the credit card owner, the contract cannot be executed and the vehicle
              cannot be delivered. In this case, the regular cancelation policy will
              apply and the full booking amount will be charged to the Hirer. The
              security deposit will be returned to the Hirer at the end of the rental
              period, after an inspection by a Rental Firm member staff, who shall
              state the vehicle is in similar conditions compared to when it was collected.
              3) Vehicle damage and equipment/extras damage costs will be charged
              according to the Rental Firm price table. The Hirer will also be liable
              for the days not rented during the vehicle reasonable repair time, according
              to the damages at issue. 4) In case of an accident where the Hirer does
              not consider himself responsible, the Rental Firm will hold the full
              amount of the security deposit until the insurance company states the
              responsibility. 5) If the damage repair costs cannot be determined immediately,
              the Rental Firm will hold the full amount of the security deposit. A
              portion of the excess can be refunded in case the final damage repair
              costs are lower than the amount paid. 6) The Hirer agrees that the Rental
              Firm is authorized to charge the credit card on file for any further
              amounts that may arise such as wild camping, parking tickets, fines,
              traffic offence penalties, tolls, damages to the van (interior or exterior)
              and overdue amounts. Rental Firm is entitled to verify any of the damages
              to the van for 30 days after the last day of the rental agreement. In
              the event of a fine, the Rental Firm will always attempt to forward
              the fine to the Hirer. On these cases, a 25€ administrative fee will
              be charged by the Rental Firm. In the event that it is not possible
              to forward the fine to the Hirer, the Rental Firm will process the fine
              and charge to the Hirer the total cost of the fine plus VAT and an added
              administrative fee of 50€. 7) Hirer must provide the Rental Firm with
              an alternative credit card that can be used to meet Hirer’s obligations
              under the Rental Firm Terms and Conditions, in case of insufficient
              funds, declined transactions for any reason, and cancelled or suspended
              credit card. 8) All unpaid invoices will be added interest, which is
              the highest legal rate plus a flat fee, corresponding to 20% of the
              unpaid amount and any compensation for occurred damages / lost profits
              due by law. In the event of a legal dispute somehow related with this
              contract, the parties agree that the jurisdiction of the pick-up location
              will be applied.
  • Column 1, section 2, text contains a trailing space.
  • Column 2, section 8, text contains a : character followed by a space.

The specification says:

The plain (unquoted) style has no identifying indicators and provides no form of escaping. It is therefore the most readable, most limited and most context sensitive style. In addition to a restricted character set, a plain scalar must not be empty, or contain leading or trailing white space characters. It is only possible to break a long plain line where a space character is surrounded by non-spaces.

...

Plain scalars must never contain the “: ” and “ #” character combinations. Such combinations would cause ambiguity with mapping key: value pairs and comments. In addition, inside flow collections, or when used as implicit keys, plain scalars must not contain the “[”, “]”, “{”, “}” and “,” characters. These characters would cause ambiguity with flow collection structures.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM